Skip to main content
Reactor によるデータインジェスチョン 
Pivotal ジャパン株式会社テクニカルサポートエンジニア北田顕啓 
@quitada 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
アジェンダ 
 Reactor とは? 
 データインジェスチョンとその課題 
 TcpServer によるデータインジェスチョンの実現 
 最後に… 
2 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
3 
Reactor とは? 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
Reactor とは? 
 Reactor ≠ 原子炉? 
• Spring Reactor のClojure インターフェース: 
 デザインパターンのReactor Pattern に影響をうける 
 Spring IO Platform のIO Foundation におけるJVM 
 Pivotal が提供する100% オープンソースプロダクト 
 2013 年11 月12 日にv1.0 GA リリース 
4 
Meltdown 
上で非同期イベント駆動型アプリケーションを構築する基 
盤フレームワーク 
• https://spring.io/platform 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
Getting Started をやってみた 
 ソースコード 
5 
Environment env = new Environment(); 
Reactor reactor = Reactors.reactor() 
.env(env) // our current Environment 
.dispatcher(Environment.RING_BUFFER) // The name of the default ring buffer dispatcher 
.get(); // get the object when finished configuring 
// Set a selector and register a consumer to handle events sent with a key that matches "parse” 
reactor.on(Selectors.$("parse"), new Consumer<Event<String>>() { 
@Override 
public void accept(Event<String> ev) { 
System.out.println("Received event with data: " + ev.getData()); 
} 
}); 
// Send an event to this Reactor and trigger all actions that match the given key 
for (int i=0; i < 100 ; i++) { 
reactor.notify("parse", Event.wrap("data" + new Integer(i).toString())); 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/ 
} 
設定値入れ物生成の 
おまじない 
Reactor インスタンス生成: 
イベントディスパッチャーは 
リングバッファーを使用 
Key-Value 型のイベントを受 
信した際のロジックを記述 
(ラムダ式も使用可能) 
100 個のイベントを投入
Getting Started 
をやってみた 
Unless otherwise indicated, these sl ides are 
© 6 
2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: 
ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/ 
REACTOR 
Demo 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
7 
データインジェスチョンとその課題 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
データインジェスチョン(Data Ingestion)とは? 
“データインジェスチョンは、データを後で使用したり、あるいは 
8 
データベースに格納するため、取得・取り込み・加工を行うこと 
である。この処理は、しばし個別のファイルを、その内容を編集 
したり、巨大ドキュメントに適合するようフォーマットを揃えると 
いった、改変処理を伴う。 
WhatIs.com より引用・翻訳 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
ビッグデータ時代におけるデータインジェスチョンの課題 
 日々大量に生成されるデータを、いかにしてリアルタイムに、遅延なく、データ 
インジェスチョンを行うか? 
• データ加工を行ったり、バックエンドのデータベースにデータ格納することを 
9 
考えると、それらがボトルネックとなる。 
• データ取得をイベントドリブンで非同期的に行い、当該データをキューイング、 
時間のかかる後処理を順次行えば良い。 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/ 
Reactor が使えそう…! 
CEP っぽい… 
北田 
Pivotal の技術で何か 
使えそうなのないかな…?
10 
TcpServer によるデータインジェスチョンの実現 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
TcpServer とは? 
 Reactor に含まれる、高速なTCP ベースのデータインジェスチョンを行うための強力 
 デフォルトのランタイムはNetty を使用しているが、他実装の使用も可能 
 コーデックサポート 
• TCP 経由で取得されるデータを変換して取り込む機構 
 Reply サポート 
11 
なサーバー側抽象レイヤー 
• 例えば、ストリームとして区切りなく流れてくる文字データを、区切り文字を与えておく 
ことによって、文字列単位で取り込む 
• データ投入クライアントに対してReply メッセージを返却 
• 姉妹品のTcpClient 使用時に有効 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
使い方- サンプルソースコードを眺めてみた 
 ソースコード 
12 
Environment env = new Environment(); 
// create a spec using the Netty-based server 
TcpServer<String, String> server = new TcpServerSpec<String, String>(NettyTcpServer.class) 
.env(env) 
.codec(StandardCodecs.LINE_FEED_CODEC) 
.listen("localhost", 15151) 
.consume(new Consumer<NetChannel<String, String>>() { 
public void accept(NetChannel<String, String> conn) { 
// for each connection, process incoming data 
conn.in().consume(new Consumer<String>() { 
public void accept(String line) { 
// handle line feed data 
} 
}); 
} 
}) 
.get(); 
server.start(); 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/ 
設定値入れ物生成の 
おまじない 
TcpServer インスタンス生成: 
Netty 適用 
使用コーデックは「文字列の 
区切りは改行コード」、リスン 
アドレス・ポートの設定 
コネクション確立時の 
イベントハンドリングを記述 
データ取得時のイベント 
TcpServer 起動ハンドリングを記述
Pivotal GemFire と組み合わせてみた 
 Pivotal GemFire とは?(以下、単にGemFire) 
 GemFire を使った大量ストリームデータのインジェスチョンを想定 
 Reactor TcpServer で非同期データ受信、必要なデータのみを 
13 
• Pivotal 社提供のJava ベース・インメモリ・データグリッド製品 
• 大量データを全てキャッシュへストア・データレプリケーションを 
同期的に行うオーバーヘッドにより期待したパフォーマンスがで 
ない懸念 
• そもそも、GemFire にストリームデータのインジェスチョンを行う 
API がない* 
選択的にGemFire キャッシュへストア 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/ 
GemFire 
キャッシュ 
GemFire 
キャッシュ 
GemFire 
キャッシュ 
データレプリケーション 
選択的にキャッシュ 
Reactor 
Reactor 
Reactor 
へストア 
大量 
ストリーム 
データ 
大量 
ストリーム 
データ 
大量 
ストリーム 
データ 
*= 最新版ではREST API はある
Pivotal GemFire 
と組み合わせて 
みた 
Unless otherwise indicated, these sl ides are 
© 14 
2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: 
ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/ 
REACTOR 
Demo 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
15 
最後に… 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
今日のまとめとやり残したこと 
 今日のまとめ 
• Reactor の概要紹介 
16 
• データインジェスチョンとReactor 
適用可能性について 
• TcpServer の概要紹介 
• GemFire とReactor の連携例紹介 
 やり残したこと 
• 他機能(Tuples、Streams、Promises、 
Processor サポート、 
AsyncTaskExecutor サポート、 
TcpClient)の網羅的紹介 
• Spring Framework を使ったReactor 
プログラミング 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/
Reactor – 技術情報 
 Reactor - a foundation for asynchronous applications on the JVM 
• http://spring.io/blog/2013/05/13/reactor-a-foundation-for-asynchronous-applications- 
 GitHub – reacor/reactor: ソースコード、ドキュメント 
• https://github.com/reactor/reactor 
 GitHub - clojurewerkz/meltdown: Clojure インターフェース 
 Google Groups: reactor-framwork 
17 
on-the-jvm/ 
• https://github.com/clojurewerkz/meltdown 
• https://groups.google.com/forum/#!forum/reactor-framework 
Unless otherwise indicated, these sl ides are © 2013-2014 Pivotal Sof tware, Inc. and l icensed under a 
Creat ive Commons At tribut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by -nc/3.0/