Upload
akihiro-kitada
View
422
Download
0
Embed Size (px)
Citation preview
Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
Reactor によるデータインジェスチョン
Pivotal ジャパン株式会社テクニカルサポートエンジニア北田 顕啓
@quitada
2Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
アジェンダ
Reactor とは?
データインジェスチョンとその課題
TcpServer によるデータインジェスチョンの実現
最後に…
3Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
Reactor とは?
4Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
Reactor とは?
Reactor ≠ 原子炉?
• Spring Reactor の Clojure インターフェース:Meltdown
デザインパターンの Reactor Pattern に影響をうける
Spring IO Platform の IO Foundation における JVM
上で非同期イベント駆動型アプリケーションを構築する基
盤フレームワーク
• https://spring.io/platform
Pivotal が提供する100% オープンソースプロダクト
2013 年 11 月 12 日に v1.0 GA リリース
5Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
Getting Started をやってみた
ソースコード
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()));
}
設定値入れ物生成のおまじない
Reactor インスタンス生成:
イベントディスパッチャーはリングバッファーを使用
Key-Value 型のイベントを受信した際のロジックを記述(ラムダ式も使用可能)
100 個のイベントを投入
6Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
Demo
Unless otherwise indicated, these sl ides are
© 2013-2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense:
http://creativecommons.org/l icenses/by -nc/3.0/
Getting Started
をやってみた
REACTOR
7Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
データインジェスチョンとその課題
8Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
データインジェスチョン(Data Ingestion)とは?
“データインジェスチョンは、データを後で使用したり、あるいは
データベースに格納するため、取得・取り込み・加工を行うことである。この処理は、しばし個別のファイルを、その内容を編集したり、巨大ドキュメントに適合するようフォーマットを揃えるといった、改変処理を伴う。
WhatIs.com より引用・翻訳
9Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
ビッグデータ時代におけるデータインジェスチョンの課題
日々大量に生成されるデータを、いかにしてリアルタイムに、遅延なく、データインジェスチョンを行うか?
• データ加工を行ったり、バックエンドのデータベースにデータ格納することを考えると、それらがボトルネックとなる。
• データ取得をイベントドリブンで非同期的に行い、当該データをキューイング、時間のかかる後処理を順次行えば良い。
Reactor が使えそう…!CEP っぽい…
北田
Pivotal の技術で何か使えそうなのないかな…?
10Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
TcpServer によるデータインジェスチョンの実現
11Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
TcpServer とは?
Reactor に含まれる、高速な TCP ベースのデータインジェスチョンを行うための強力
なサーバー側抽象レイヤー
デフォルトのランタイムは Netty を使用しているが、他実装の使用も可能
コーデックサポート
• TCP 経由で取得されるデータを変換して取り込む機構
• 例えば、ストリームとして区切りなく流れてくる文字データを、区切り文字を与えておくことによって、文字列単位で取り込む
Reply サポート
• データ投入クライアントに対して Reply メッセージを返却
• 姉妹品の TcpClient 使用時に有効
12Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
使い方 -サンプルソースコードを眺めてみた
ソースコード
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();
設定値入れ物生成のおまじない
TcpServer インスタンス生成:
Netty適用
使用コーデックは「文字列の区切りは改行コード」、リスンアドレス・ポートの設定
コネクション確立時のイベントハンドリングを記述
データ取得時のイベントハンドリングを記述TcpServer起動
13Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
Pivotal GemFire と組み合わせてみた
Pivotal GemFire とは?(以下、単に GemFire)
• Pivotal 社提供の Java ベース・インメモリ・データグリッド製品
GemFire を使った大量ストリームデータのインジェスチョンを想定
• 大量データを全てキャッシュへストア・データレプリケーションを
同期的に行うオーバーヘッドにより期待したパフォーマンスがで
ない懸念
• そもそも、GemFireにストリームデータのインジェスチョンを行う
API がない*
Reactor TcpServerで非同期データ受信、必要なデータのみを
選択的に GemFireキャッシュへストア
GemFire
キャッシュ
GemFire
キャッシュ
GemFire
キャッシュ
データレプリケーション
Reactor
Reactor
Reactor
大量ストリームデータ
大量ストリームデータ
大量ストリームデータ
選択的にキャッシュへストア
*= 最新版では REST API はある
14Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
Demo
Unless otherwise indicated, these sl ides are
© 2013-2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense:
http://creativecommons.org/l icenses/by -nc/3.0/
Pivotal GemFire
と組み合わせてみた
REACTOR
15Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
最後に…
16Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/l icenses/by -nc/3.0/
今日のまとめとやり残したこと
今日のまとめ
• Reactor の概要紹介
• データインジェスチョンと Reactor
適用可能性について
• TcpServerの概要紹介
• GemFire とReactor の連携例紹介
やり残したこと
• 他機能(Tuples、Streams、Promises、Processor サポート、AsyncTaskExecutor サポート、TcpClient)の網羅的紹介
• Spring Framework を使った Reactor
プログラミング
17Unless otherwise indicated, these sl ides are © 2013 -2014 Pivotal Software, Inc. and l icensed under a
Creative Commons Attribution-NonCommercial l icense: http://creativecommons.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-on-the-jvm/
GitHub – reacor/reactor: ソースコード、ドキュメント
• https://github.com/reactor/reactor
GitHub - clojurewerkz/meltdown: Clojure インターフェース
• https://github.com/clojurewerkz/meltdown
Google Groups: reactor-framwork
• https://groups.google.com/forum/#!forum/reactor-framework