Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
2017年7月5日
ヤフー株式会社 小舘 航
DataWorks Summit 2017 San Jose
ストリーム処理関連の報告
Hadoopソースコードリーディング 第23回
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
自己紹介
2
• 小舘 航(こだて わたる) @hbwandeow
• 2012年入社
• 社内ストリーム処理プラットフォームの開発・運用
• ストリーム処理アプリケーションの開発
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
アジェンダ
1. DataWorks Summit概要
2. セッション紹介
1. Realizing the promise of portable data processing
with Apache Beam / Google
2. Next Generation Execution Engine for Apache
Storm / Hortonworks
3. まとめ
3
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
アジェンダ
1. DataWorks Summit概要
2. セッション紹介
1. Realizing the promise of portable data processing
with Apache Beam / Google
2. Next Generation Execution Engine for Apache
Storm / Hortonworks
3. まとめ
4
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
DataWorks Summit 2017 San Jose
5
• 日時: 2017年6月13日-15日
• 場所: San Jose McEnery Convention Center
• Hadoop Summit→DataWorks Summitに名称を変更
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
イベント詳細
6
• Keynotes+170以上のBreakout sessions
• 発表スライド: https://dataworkssummit.com/san-jose-2017/agenda/
• Training / Crash Course
• Meetup / Bird of a Feather
• 主にストリーム処理関連のセッションを聴講
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
ストリーム処理とは
• 無限に流れてくるデータを処理し続ける
• バッチ処理と比較して速さに価値がある
• ユースケース
• リアルタイム集計、異常検知
例) クリック率急増の検知、Abuserの検知
• 機械学習
例) 商品のレコメンデーション、広告のクリック率予測
• ETL
例) 話題のハッシュタグトップ10
7
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
全体を通しての感想
• 世界の企業では、ストリーム処理はデータ分析プラットフォームの中で当たり
前に使われている。年々、プロダクションでの事例も増えてきており、扱う
データ量やクラスタの規模も大きくなっている
• 主に使われていたストリーム処理実行エンジンはStorm, Spark Streaming,
Flink
• 求められているストリーム処理プラットフォームの特徴
• 低レイテンシ
• 容易な分析インターフェース
• データの完全性
• バッチとの統合
• サイエンス
8
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
アジェンダ
1. DataWorks Summit概要
2. セッション紹介
1. Realizing the promise of portable data processing
with Apache Beam / Google
2. Next Generation Execution Engine for Apache
Storm / Hortonworks
3. まとめ
9
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
Apache Beam
• Realizing the promise of portable data processing with
Apache Beam / Google
• バッチ処理とストリーム処理を任意のエンジンで実行でき
るモデルを提供
• 2017/05/17 First stable release
• 特徴
1. Unified
2. Portable
3. Extensible
10
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
1. Unified: Beamモデル
• バッチ処理とストリーム処理を同様のモデルで定義
• パイプラインを構築する際に考える必要がある質問
1. What results are calculated?
2. Where in event time are results calculated?
3. When in processing time are results
materialized?
4. How do refinements of results relate?
11
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
Processing time vs Event time
12
・Processing time
システムが処理した時間
・Event time
イベントが発生した時間
・必ずしもイベントの発生順にシステムが処理するわけではない
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
13
What is being computed?
変換処理は何か
・ParDo
・GroupByKey
・Combine
・Flatten, Partition
…
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
14
Where in event time?
どこをWindowとするか
・Global windows
・Fixed windows
・Sliding windows
・Session windows
…
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
15
When in processing time?
いつWindow処理を終了するか
・Watermark
Windowの全てのデータが
処理されたとみなす時間
・Trigger
Windowのデータを出力する
タイミング
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
16
How do refinement relate?
どのようにWindowの結果を
反映させるか
・Discarding
・Accumulating
・Accumulating & Retracting
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
Beamモデルまとめ
17
変換処理は何か どこをWindow
とするか
いつWindow処理を
終了するか
どのようにWindowの
結果を反映させるか
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
具体的な例1
18
• 有限の入力データに対するワードカウント(Classic Batch)
• What?
単語のキーに対する整数の合計
• Where?
単一のグローバルウィンドウ
• When?
有限な入力データセットが処理された後に1回
• How?
ウィンドウに対して1度出力されるので関係なし
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
具体的な例2
19
• 有限の入力データに対する1時間毎のワードカウント (Windowed
Batch)
• What?
単語のキーに対する整数の合計
• Where?
1時間のEvent timeの固定ウィンドウ
• When?
有限な入力データセットが処理された後に1回
• How?
ウィンドウに対して1度出力されるので関係なし
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
具体的な例3
20
• 無限の入力データに対する1時間毎のワードカウント
(Streaming + Accumulation)
• What?
単語のキーに対する整数の合計
• Where?
1時間のEvent timeの固定ウィンドウ
• When?
• Early: 5分毎のProcessing time
• On-time: Watermarkがウィンドウの最後を通過したとき
• Late: 1分毎のProcessing time
• Final: Watermarkがウィンドウの最後を通過してから2時間後
• How?
前の値に新しい値を累積
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
2. Portable
21
• ユーザが各言語SDKを選
択可能
• Runnerを選択可能
Runnerによって実装可能
な処理が異なる
• 同じソースコードを使って異なるRunnerで実行可能
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
How do you build an abstraction layer?
22
• 各Runnerの共通部分だけでなく、Runnerに合った処理に
変換できるような役割を目指している
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
3. Extensible
• Read/Writeするカスタムソースを定義できる
• SDKs
• Runner
23
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
I/O Transforms
• Built-in I/O
• In-Progress I/O
24
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
Beamプログラムの実行
1. Pipelineオブジェクトの作成と実行オプションの選択
2. Source APIを使ってPCollectionを初期化
3. PCollectionにTransformを適用
4. Sink APIを使って、変換処理されたPCollectionを出力
5. Pipeline RunnerでPipelineを実行
25
Source Sink
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
アジェンダ
1. DataWorks Summit概要
2. ストリーム処理
3. セッション紹介
1. Realizing the promise of portable data processing
with Apache Beam / Google
2. Next Generation Execution Engine for Apache
Storm / Hortonworks
4. まとめ
26
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
Apache Storm
• Next Generation Execution Engine for Apache Storm /
Hortonworks
• 2011年にTwitter社が公開
• 古くからあるストリーム処理実行エンジン
• 現在productionで広く利用されている
27
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
Storm 1.X
• Improved Performance(16x faster throughput)
• Pacemaker
• Distributed Cache API
• HA Nimbus
• Window API
• Backpressure
• Resource Aware Scheduler
• Storm Usability Improvements
• …
28
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
Storm 2.0
• High performance execution engine
• All Java code(transition away from Clojure)
• Improved Backpressure, Metrics subsystems
• Beam integration, Bounded spouts
• Scheduling Hints, Elasticity
• Dynamic Topology Updates
• …
29
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
Performance in 2.0
• メッセージングアーキテクチャの変更(STORM-2306)
• ハイパフォーマンスな内部Queueを選択
• スレッド内の過剰なQueue(主にExecutor内のSend
Queue)を削除
→レイテンシが116xに向上
• Executor, Threadモデルの変更(STORM-2307)
• 同じexecutor threadに異なるタイプのタスクを実行す
ることが可能。タスク間通信を最適化
30
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
Scheduling & Elasticity(STORM-2309)
• Worker内部やWorkerをまたがるタスクの実行を最適化した
い
• Parallelism hints
• Worker毎、ホスト毎、クラスタ全体で並列数を設定
• LocalityControl
• タスクの配置場所を制御
• グルーピングの引数で分散を制御
• shuffle(threadLocal)
• fieldsGrouping(nodeLocal)
31
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
Back-Pressure Handling(STORM-2310)
• 後続で処理が詰まらないようにイベントの流量を制御する機構
バージョン1.0から搭載された機能
• データを破棄する
• 古いイベントを破棄、新しいイベントを破棄、データソースのイ
ベントを破棄。これらはアプリケーションの特性に依存
• スケールアウトする
• 処理が追いついていない場合に、自動でプロセスやスレッド、マ
シンを増やす
• 流量を調整する
• 全てのコンポーネントではなく、処理が遅いコンポーネントのみ
前段に伝える
• 受け取るBoltのQueueが詰まっていたら前段からリトライ処理
32
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
アジェンダ
1. DataWorks Summit概要
2. セッション紹介
1. Realizing the promise of portable data processing
with Apache Beam / Google
2. Next Generation Execution Engine for Apache
Storm / Hortonworks
3. まとめ
33
Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved.
まとめ
• ストリーム処理の一般化、利用規模の拡大。低レイテンシ
+αなプラットフォームが求められる
• Apache Beamはバッチ処理とストリーム処理を統合したモ
デルを提供。開発者に合ったSDKや実行エンジンを選択
し、処理パイプラインをBeamモデルで定義する
• Storm2.0からJavaコードに置き換え。実行プロセスの内部
アーキテクチャが変更され、パフォーマンスが向上
34

Dataworks Summit 2017 SanJose StreamProcessing - Hadoop Source Code Reading #23 #hadoopreading

  • 1.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. 2017年7月5日 ヤフー株式会社 小舘 航 DataWorks Summit 2017 San Jose ストリーム処理関連の報告 Hadoopソースコードリーディング 第23回
  • 2.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. 自己紹介 2 • 小舘 航(こだて わたる) @hbwandeow • 2012年入社 • 社内ストリーム処理プラットフォームの開発・運用 • ストリーム処理アプリケーションの開発
  • 3.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. アジェンダ 1. DataWorks Summit概要 2. セッション紹介 1. Realizing the promise of portable data processing with Apache Beam / Google 2. Next Generation Execution Engine for Apache Storm / Hortonworks 3. まとめ 3
  • 4.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. アジェンダ 1. DataWorks Summit概要 2. セッション紹介 1. Realizing the promise of portable data processing with Apache Beam / Google 2. Next Generation Execution Engine for Apache Storm / Hortonworks 3. まとめ 4
  • 5.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. DataWorks Summit 2017 San Jose 5 • 日時: 2017年6月13日-15日 • 場所: San Jose McEnery Convention Center • Hadoop Summit→DataWorks Summitに名称を変更
  • 6.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. イベント詳細 6 • Keynotes+170以上のBreakout sessions • 発表スライド: https://dataworkssummit.com/san-jose-2017/agenda/ • Training / Crash Course • Meetup / Bird of a Feather • 主にストリーム処理関連のセッションを聴講
  • 7.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. ストリーム処理とは • 無限に流れてくるデータを処理し続ける • バッチ処理と比較して速さに価値がある • ユースケース • リアルタイム集計、異常検知 例) クリック率急増の検知、Abuserの検知 • 機械学習 例) 商品のレコメンデーション、広告のクリック率予測 • ETL 例) 話題のハッシュタグトップ10 7
  • 8.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. 全体を通しての感想 • 世界の企業では、ストリーム処理はデータ分析プラットフォームの中で当たり 前に使われている。年々、プロダクションでの事例も増えてきており、扱う データ量やクラスタの規模も大きくなっている • 主に使われていたストリーム処理実行エンジンはStorm, Spark Streaming, Flink • 求められているストリーム処理プラットフォームの特徴 • 低レイテンシ • 容易な分析インターフェース • データの完全性 • バッチとの統合 • サイエンス 8
  • 9.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. アジェンダ 1. DataWorks Summit概要 2. セッション紹介 1. Realizing the promise of portable data processing with Apache Beam / Google 2. Next Generation Execution Engine for Apache Storm / Hortonworks 3. まとめ 9
  • 10.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. Apache Beam • Realizing the promise of portable data processing with Apache Beam / Google • バッチ処理とストリーム処理を任意のエンジンで実行でき るモデルを提供 • 2017/05/17 First stable release • 特徴 1. Unified 2. Portable 3. Extensible 10
  • 11.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. 1. Unified: Beamモデル • バッチ処理とストリーム処理を同様のモデルで定義 • パイプラインを構築する際に考える必要がある質問 1. What results are calculated? 2. Where in event time are results calculated? 3. When in processing time are results materialized? 4. How do refinements of results relate? 11
  • 12.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. Processing time vs Event time 12 ・Processing time システムが処理した時間 ・Event time イベントが発生した時間 ・必ずしもイベントの発生順にシステムが処理するわけではない
  • 13.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved.Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved. 13 What is being computed? 変換処理は何か ・ParDo ・GroupByKey ・Combine ・Flatten, Partition …
  • 14.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved.Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved. 14 Where in event time? どこをWindowとするか ・Global windows ・Fixed windows ・Sliding windows ・Session windows …
  • 15.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved.Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved. 15 When in processing time? いつWindow処理を終了するか ・Watermark Windowの全てのデータが 処理されたとみなす時間 ・Trigger Windowのデータを出力する タイミング
  • 16.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved.Copyrig ht © 2017 Yahoo Japan Corporation. All Rig hts Reserved. 16 How do refinement relate? どのようにWindowの結果を 反映させるか ・Discarding ・Accumulating ・Accumulating & Retracting
  • 17.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. Beamモデルまとめ 17 変換処理は何か どこをWindow とするか いつWindow処理を 終了するか どのようにWindowの 結果を反映させるか
  • 18.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. 具体的な例1 18 • 有限の入力データに対するワードカウント(Classic Batch) • What? 単語のキーに対する整数の合計 • Where? 単一のグローバルウィンドウ • When? 有限な入力データセットが処理された後に1回 • How? ウィンドウに対して1度出力されるので関係なし
  • 19.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. 具体的な例2 19 • 有限の入力データに対する1時間毎のワードカウント (Windowed Batch) • What? 単語のキーに対する整数の合計 • Where? 1時間のEvent timeの固定ウィンドウ • When? 有限な入力データセットが処理された後に1回 • How? ウィンドウに対して1度出力されるので関係なし
  • 20.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. 具体的な例3 20 • 無限の入力データに対する1時間毎のワードカウント (Streaming + Accumulation) • What? 単語のキーに対する整数の合計 • Where? 1時間のEvent timeの固定ウィンドウ • When? • Early: 5分毎のProcessing time • On-time: Watermarkがウィンドウの最後を通過したとき • Late: 1分毎のProcessing time • Final: Watermarkがウィンドウの最後を通過してから2時間後 • How? 前の値に新しい値を累積
  • 21.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. 2. Portable 21 • ユーザが各言語SDKを選 択可能 • Runnerを選択可能 Runnerによって実装可能 な処理が異なる • 同じソースコードを使って異なるRunnerで実行可能
  • 22.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. How do you build an abstraction layer? 22 • 各Runnerの共通部分だけでなく、Runnerに合った処理に 変換できるような役割を目指している
  • 23.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. 3. Extensible • Read/Writeするカスタムソースを定義できる • SDKs • Runner 23
  • 24.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. I/O Transforms • Built-in I/O • In-Progress I/O 24
  • 25.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. Beamプログラムの実行 1. Pipelineオブジェクトの作成と実行オプションの選択 2. Source APIを使ってPCollectionを初期化 3. PCollectionにTransformを適用 4. Sink APIを使って、変換処理されたPCollectionを出力 5. Pipeline RunnerでPipelineを実行 25 Source Sink
  • 26.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. アジェンダ 1. DataWorks Summit概要 2. ストリーム処理 3. セッション紹介 1. Realizing the promise of portable data processing with Apache Beam / Google 2. Next Generation Execution Engine for Apache Storm / Hortonworks 4. まとめ 26
  • 27.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. Apache Storm • Next Generation Execution Engine for Apache Storm / Hortonworks • 2011年にTwitter社が公開 • 古くからあるストリーム処理実行エンジン • 現在productionで広く利用されている 27
  • 28.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. Storm 1.X • Improved Performance(16x faster throughput) • Pacemaker • Distributed Cache API • HA Nimbus • Window API • Backpressure • Resource Aware Scheduler • Storm Usability Improvements • … 28
  • 29.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. Storm 2.0 • High performance execution engine • All Java code(transition away from Clojure) • Improved Backpressure, Metrics subsystems • Beam integration, Bounded spouts • Scheduling Hints, Elasticity • Dynamic Topology Updates • … 29
  • 30.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. Performance in 2.0 • メッセージングアーキテクチャの変更(STORM-2306) • ハイパフォーマンスな内部Queueを選択 • スレッド内の過剰なQueue(主にExecutor内のSend Queue)を削除 →レイテンシが116xに向上 • Executor, Threadモデルの変更(STORM-2307) • 同じexecutor threadに異なるタイプのタスクを実行す ることが可能。タスク間通信を最適化 30
  • 31.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. Scheduling & Elasticity(STORM-2309) • Worker内部やWorkerをまたがるタスクの実行を最適化した い • Parallelism hints • Worker毎、ホスト毎、クラスタ全体で並列数を設定 • LocalityControl • タスクの配置場所を制御 • グルーピングの引数で分散を制御 • shuffle(threadLocal) • fieldsGrouping(nodeLocal) 31
  • 32.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. Back-Pressure Handling(STORM-2310) • 後続で処理が詰まらないようにイベントの流量を制御する機構 バージョン1.0から搭載された機能 • データを破棄する • 古いイベントを破棄、新しいイベントを破棄、データソースのイ ベントを破棄。これらはアプリケーションの特性に依存 • スケールアウトする • 処理が追いついていない場合に、自動でプロセスやスレッド、マ シンを増やす • 流量を調整する • 全てのコンポーネントではなく、処理が遅いコンポーネントのみ 前段に伝える • 受け取るBoltのQueueが詰まっていたら前段からリトライ処理 32
  • 33.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. アジェンダ 1. DataWorks Summit概要 2. セッション紹介 1. Realizing the promise of portable data processing with Apache Beam / Google 2. Next Generation Execution Engine for Apache Storm / Hortonworks 3. まとめ 33
  • 34.
    Copyrig ht ©2017 Yahoo Japan Corporation. All Rig hts Reserved. まとめ • ストリーム処理の一般化、利用規模の拡大。低レイテンシ +αなプラットフォームが求められる • Apache Beamはバッチ処理とストリーム処理を統合したモ デルを提供。開発者に合ったSDKや実行エンジンを選択 し、処理パイプラインをBeamモデルで定義する • Storm2.0からJavaコードに置き換え。実行プロセスの内部 アーキテクチャが変更され、パフォーマンスが向上 34