Weitere ähnliche Inhalte
Ähnlich wie Treasure Dataを支える技術 - MessagePack編 (20)
Mehr von Taro L. Saito (20)
Kürzlich hochgeladen (11)
Treasure Dataを支える技術 - MessagePack編
- 1. Treasure Dataを支える技術 -
MessagePack編
Taro L. Saito, Treasure Data
leo@treasure-data.com
December 11, 2014
ビッグデータ基盤勉強会@NTT武蔵野開発センター
Copyright ©2014 Treasure Data. All Rights Reserved.
- 2. 自己紹介 @taroleo
• 2002 東京大学 理学部 情報科学科卒
• 2007 Ph.D.
– XMLデータベース(SIGMOD’08)、トランザクション処理の研究
• ~ 2014 東京大学 情報生命科学専攻 助教
– ゲノムサイエンス研究
• 大規模データ処理、並列・分散コンピューティング
• 2014.3月~ Treasure Data
– ソフトウェアエンジニア, MPP Team Leader
Copyright ©2014 Treasure Data. All Rights Reserved.
2
- 3. 「データベース」に関連するオープンソース活動
• sqlite-jdbc
– SQLite DBMS for Java
– 1ファイル=1DB
Copyright ©2014 Treasure Data. All Rights Reserved.
• snappy-java
– 高速圧縮ライブラリ
– 月に10万回以上ダウンロード
– Sparkでも採用
• msgpack-java
• UT Genome Browser (UTGB)
– 大規模ゲノム情報の可視化
3
- 4. Treasure Dataとは?
• 米シリコンバレー発日本人創業のビッグデータ関連企業
– 2011年12月、米Mountain Viewにて創業
– 2012年11月、東京丸の内に日本支社設立
• クラウド型データマネージメントサービス「Treasure Data Service」を提供
Copyright ©2014 Treasure Data. All Rights Reserved.
4
芳川裕誠 – CEO
Open source business veteran
太田一樹 – CTO
Founder of world’s largest Hadoop Group
主要投資家
Sierra Ventures – (Tim Guleri)
企業向けソフト・データベース領域での有力VC
Bill Tai
Charles River Ventures, Twitterなどに投資
まつもとゆきひろ
Ruby言語開発者
創業者
Jerry Yang
Yahoo! Inc. 創業者
古橋貞之 – Software Engineer
MessagePack, Fluentd開発者
- 5. Treasure Data Service
ビッグデータのための「クラウド + マネジメント」一体型サービス
データ収集~保存~分析までワンストップでサポート
Copyright ©2014 Treasure Data. All Rights Reserved.
5
• 毎日数百億規模のレコードが取り込まれている
– 2014年5月に5兆(trillion)レコードに到達
• SQLベース(Hive, Presto, Pigなど)による検索サービスを提供
- 6. Impressive Momentum
Copyright ©2014 Treasure Data. All Rights Reserved.
7000
6000
5000
4000
3000
2000
1000
0
Data Growth in Billions
Data (records) Imported
Service
Launched
4 Trillion
3 Trillion
1 Trillion
5 Trillion
2 Trillion
Series A Funding
Gartner Cool
100
Customers
Vendor
Report
6
- 9. Claremont Report on Database Research
• データベースの研究者、ユーザー、
識者が今後のDBMSについて議論
– CACM, Vol. 52 No. 6, 2009
• Cloud Data Serviceの発展を予測
– SQLの重要な役割
• 機能を制限できる
• サービスとして提供するには好都合
– 難しい例:Spark
• 任意のコードを実行させるためのセ
キュアなコンテナ開発が別途必要
Copyright ©2014 Treasure Data. All Rights Reserved.
9
- 10. Beckman Report on Database Research
• 2013年版
– http://beckman.cs.wisc.edu/beckman-report2013.pdf
– ほぼ全面Big Dataについての話題
Copyright ©2014 Treasure Data. All Rights Reserved.
• End-to-end
– データの収集から、knowledgeまで生み出す
• Cloud Serviceの普及
– IaaS, PaaS, SaaS
– DBMSの全てをクラウドで、という理想にはまだ到達していない
• DB教育にも言及
– 70, 80年代のシステムの紹介から脱するべき
– DBの技術は、分散システム、Hadoopなど他分野にも価値があることを理
解すべき
10
- 11. Big Data Simplified: The Treasure Data Approach
Infinite & Economical
Cloud Data Store
Treasure Agent Treasure Agent
Copyright ©2014 Treasure Data. All Rights Reserved.
SQL
SQL-based Dashboards
Results Push
Results Push
App Servers
Multi-structured Events!
• register!
• login!
• start_event!
• purchase!
• etc!
DBs & Data Marts
SQL-based
Ad-hoc Queries
Other Apps
Familiar &
Table-oriented
ü App log data!
ü Mobile event data!
ü Sensor data!
ü Telemetry!
Web SDK
Mobile SDKs
Treasure Agent
structured Events
Treasure Agent
Multi-structured Events Multi-Treasure Agent
Treasure Agent
Treasure Agent
Treasure Agent
Embedded SDKs
Server-side Agents
11
- 12. Treasure Dataの基盤技術
• データを「正しく集める」
Copyright ©2014 Treasure Data. All Rights Reserved.
– Fluentd
• ログコレクター
• タグ -> JSON or MessagePack形式のログ(データ)
– PlazmaDB
• Columnar DB
• MessagePack + Compression
• データを「手軽に解析する」
– クラウド上での分散クエリエンジン
• Hive, Presto, Pigベース
12
- 13. Fluentd: データを正しく集めるための入り口
• 基本:JSON・MessagePack形式のデータを受け取る
– 種々のinput/output plugin
• メッセージのルーティング
– メッセージに付けられたタグ毎に送り先を切り替えられる
Copyright ©2014 Treasure Data. All Rights Reserved.
13
fluentd.org
- 14. Multi-structured Events
Copyright ©2014 Treasure Data. All Rights Reserved.
Multi-structured Events
Agent
Server-side Agents!
Javascript SDK!
Collectors
Mobile / Embedded SDKs!
Web File Uploader!
Bulk Loader
Bulk Importers!
Small Files
For the latest list
http://docs.treasuredata.com
14
- 15. TDのバックエンドストレージ
import SQL Query
• Real-Time Storage
– 直近のデータ (MessagePack format)
Copyright ©2014 Treasure Data. All Rights Reserved.
• Archive Storage
– 過去のデータ, MapReduceでcolumnarに分解、圧縮 (MessagePack + gzipなど)
– もともとのサイズ(json形式)の10分の1程度になる
15
Real-time
Storage
Archive
Storage
23c82b0ba3405d4c15aa85d2190e
6d7b1482412ab14f0332b8aee119
8a7bc848b2791b8fd603c719e54f
0e3d402b17638477c9a7977e7dab
...
2012-10-08 00:23:00 912ec80
2012-10-09 00:01:00 277a259
...
1時間毎にmerge
- 16. Object Storage + Index
import SQL Query
Copyright ©2014 Treasure Data. All Rights Reserved.
• Storage
– Amazon S3を利用。S3互換のRiak CS (Basho)も利用できる
– HTTP経由のデータ通信
• Object Index: PostgreSQLを使用
– S3ファイルのリスト列挙操作は遅いため
– ユーザー毎、時系列毎の範囲で検索するためにGiST indexを利用
16
Real-time
Storage
Archive
Storage
23c82b0ba3405d4c15aa85d2190e
6d7b1482412ab14f0332b8aee119
8a7bc848b2791b8fd603c719e54f
0e3d402b17638477c9a7977e7dab
...
2012-10-08 00:23:00 912ec80
2012-10-09 00:01:00 277a259
...
1時間毎にmerge
- 18. time ip : string code : int action : string
2014-09-21 10:14:33 135.52.211.23 15 upload
2014-09-21 10:14:33 45.25.38.156 -1 temp
2014-09-21 10:14:34 97.12.76.55 99 null
2014-09-21 10:14:36 76.121.9.35 21 event
Collectors PlazmaDB
Copyright ©2014 Treasure Data. All Rights Reserved.
Agent
ü Familiar Tables
18
- 19. time ip : string code : int action : string
2014-09-21 10:14:33 135.52.211.23 15 upload
2014-09-21 10:14:33 45.25.38.156 -1 temp
2014-09-21 10:14:34 97.12.76.55 99 null
2014-09-21 10:14:36 76.121.9.35 21 event
2014-09-21 11:27:41 97.12.76.55 99 null
2014-09-21 11:27:42 45.25.38.156 -1 temp
2014-09-21 11:27:42 135.52.211.23 15 upload
2014-09-21 12:02:18 97.12.76.55 99 null
2014-09-21 12:02:18 45.25.38.156 -1 temp
2014-09-21 12:02:19 135.52.211.23 15 upload
Collectors
ü Familiar Tables
ü Time-based Partitioning
Copyright ©2014 Treasure Data. All Rights Reserved.
Agent
Query
Partition
Pruning
PlazmaDB
19
- 20. time ip : string code : int action : string status : string
2014-09-21 10:14:33 135.52.211.23 15 upload null
2014-09-21 10:14:33 45.25.38.156 -1 temp null
2014-09-21 10:14:34 97.12.76.55 99 null null
2014-09-21 10:14:36 76.121.9.35 21 event null
2014-09-21 11:27:41 97.12.76.55 99 null null
2014-09-21 11:27:42 45.25.38.156 -1 temp null
2014-09-21 11:27:42 135.52.211.23 15 upload null
2014-09-21 12:02:18 97.12.76.55 99 null null
2014-09-21 12:02:18 45.25.38.156 -1 temp null
2014-09-21 12:02:19 135.52.211.23 15 upload null
2014-09-21 12:03:24 76.34.123.54 13 status ok
2014-09-21 12:03:25 92.67.7.113 13 status error
2014-09-21 12:04:51 135.52.211.23 15 upload null
Collectors PlazmaDB
ü Familiar Tables
ü Time-based Partitioning
ü Schema-Flexible
Copyright ©2014 Treasure Data. All Rights Reserved.
Agent
20
- 21. MessagePack
Copyright ©2014 Treasure Data. All Rights Reserved.
21
• レコードはMessagePack形式
• 入力時のデータ型はそのまま保存
– intやstring型のデータが列中に混在した状況でも使える
PlazmaDBがスキーマに合わせて自動型変換を行う
- 22. MessagePack Format Types
• 0x00 ~ 0x7f int
Copyright ©2014 Treasure Data. All Rights Reserved.
– 1 byte
• 0xe0 ~ 0xff neg int
– 1 byte
• Support
fixed/variable length
data
22
- 23. Dynamic Data Type Conversion
SELECT 54 (int)
(Explicit) Schema user:int name:string value:int
Copyright ©2014 Treasure Data. All Rights Reserved.
23
NULL
{“user”:54, “name”:”test”, “value”:”120”, “host”:”local”}
データ(JSON)
“test” (string) 120 (int)
host:int
- 24. Implicit / Explicit Schema
• Implicit Schema
– スキーマは自動的に付与される
– 入力されたデータ列から自動的に決定
– ユーザーはスキーマ定義なしにデータを放り込める
• Explicit Schema
– 明示的にカラムに型を設定できる
• 変換可能でない場合はNULLとして出力される
– スキーマ変更への柔軟さ
Copyright ©2014 Treasure Data. All Rights Reserved.
24
- 25. Non-1NF Type (NF^2) Support
• Array types
Copyright ©2014 Treasure Data. All Rights Reserved.
– [1, 2, … ]
• Map types
– {id:1, name:leo, address:[xxxx, yyyy]}
• In SQL
– JSON-based interface
25
- 31. MessagePackの高速化
• なぜ高速化するのか?
• 例:2割速くなる => マシン台数を2割減らせる
– 大幅なコストダウン
• クエリ処理も速くなる
– 全体のスループット向上
Copyright ©2014 Treasure Data. All Rights Reserved.
31
- 32. MessageBuffer
• 内部用buffer
• Javaのheapメモリに直接アクセス
• sun.misc.Unsafe
– byte[]中の任意の位置のデータを特定
のprimitive typeにcastできる
– JavaでDBを作りたいなら必須の機能
Copyright ©2014 Treasure Data. All Rights Reserved.
32
- 34. なぜByteBufferは遅いのか?
• 良いプログラミング作法
– interfaceを定義して、派生クラスによる実装を用意する
– 例: ByteBufferにはHeapByteBuffer, DirectByteBufferなどの実装がクラ
スパスに存在
• 現実:TypeProfile
– どの派生クラスのコードが呼び出されるか実行時に判定
– JVMでTypeProfileが生成され、table lookupのコストが余計に必要
– 遅くなる!
• MessageBufferのlittle endian版はTypeProfileを生成しないので高速
Copyright ©2014 Treasure Data. All Rights Reserved.
34
- 35. Format Typeの確認
• Unpackerで必要
– prefixを1 byte 読んで
データタイプを判定
Copyright ©2014 Treasure Data. All Rights Reserved.
• 自然な実装
– switch-case
• ANTLRが生成するlexer/
parserはこのパターンの
コード
35
- 36. Format Typeの確認
• lookup tableを作成 - cacheの活用 – 20000x faster!
Copyright ©2014 Treasure Data. All Rights Reserved.
36
- 38. MessagePack v07
• Value interface
– Integer, Float, Array, Map, ExtendedValue, etc.
– Query Result -> Value -> ResultOutput
• TDではクエリ結果(Valueで表現)をCSV, JSON, S3, RDBMS, Tableau Server
用フォーマットなどに変換して出力している
• msgpack-jackson
– オブジェクトデータをMessagePack形式でserialize/deserialize
– v06にあったコード生成テンプレート機能
• 廃止へ
• 維持が大変、javassistで生成されるコードをクラスローダーに読ませる部分
が難しいなど、様々な課題
Copyright ©2014 Treasure Data. All Rights Reserved.
38
- 39. MessagePack Hackathon at Silicon Valley
• SV
– @frsyuki
– @oza_x86
– @hkmurakami
– @taroleo
Copyright ©2014 Treasure Data. All Rights Reserved.
• JP
– @komamitsu
39
- 42. Treasure Dataが目指すもの
• 「世の中の誰もが手軽にデータベースを使える」ようにする
• まずは誰もが「データを手軽に正しく集められる」ように
– Fluentd+msgpackで柔軟にデータを取り込む
• そして誰もが「データを手軽に解析」できる
ように
– 分散SQLエンジン
• Hive, Presto
– plazmadbによるcolumnar storage, MessagePack
Copyright ©2014 Treasure Data. All Rights Reserved.
• A lot more …
WE ARE HIRING!
42