More Related Content Similar to Apache Hiveの今とこれから
Similar to Apache Hiveの今とこれから (20) More from Yifeng Jiang (20) Apache Hiveの今とこれから1. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Apache Hiveの今とこれから
Yifeng Jiang
Solutions Engineer, Hortonworks, inc.
June 11, 2015
2. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
自己紹介
蒋 逸峰 (Yifeng Jiang)
• Solutions Engineer @ Hortonworks Japan
• HBase book author
• ⽇日本に来て10年年経ちました…
• 趣味は⼭山登り
• Twitter: @uprush
3. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
アジェンダ
• Apache Hiveの今
• 100倍早くなった仕組み
• 1秒以下のレスポンスを実現していく
4. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
専門家集団: 開発に深く携わるコア・メンバーにより構成
沿革
2011年6月:
Yahoo! で初代の Hadoop 開発を手がけたアーキテクト、デベロッパー、
オペレータ 24名によって創立
2014年12月:
社員数600を超えるHadoopの専門家集団に成長
400以上のお客様、うち2/3はF1000企業
Apache Project Committers
PMC
Members
Hadoop 27 21
Pig 5 5
Hive 18 6
Tez 16 15
HBase 6 4
Phoenix 4 4
Accumulo 2 2
Storm 3 2
Slider 11 11
Falcon 5 3
Flume 1 1
Sqoop 1 1
Ambari 36 28
Oozie 3 2
Zookeeper 2 1
Knox 13 3
Ranger 11 n/a
TOTAL 164 109
6. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Hortonworks Data Platform (HDP) 2.2 Stack
Hive: SQL on Hadoop
7. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Apache Hiveの今
Transaction, Temp Table, Security, Performance
8. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Apache Hiveを振り返てみる
Page 8Hive & HBase For Transaction Processing
• Facebook社がOSS化したHadoop上のSQLデータ・ウェアハウス
• 2009年年にApache Hiveとしてはじめのリリース
• 最初のゴールはSQL⾔言語でMapReduceを簡単に実⾏行行できるように
– ほとんどのクエリが数分から数時間かかっていた
– 主にバッチのETLジョブに利利⽤用されてた
9. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Hive – 1つのツールですべてのSQLユースケース
OLTP,
ERP,
CRM
Systems
Unstructured
documents,
emails
Clickstream
Server
logs
Sen>ment,
Web
Data
Sensor.
Machine
Data
Geoloca>on
インタラクティブ
分析
バッチレポート/
ディープ分析
Hive - SQL
ETL処理
10. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
あらゆるワークロードまでスケールするHive
Page 10
Hive at Facebook
• 100PB以上のデータ
• 毎⽇日15TB以上をHiveにロード
• 毎⽇日6万以上のHiveクエリ実⾏行行
• 毎⽇日1千以上のHiveユーザーが利利⽤用
11. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
トランザクション
Insert, Update and Delete SQL Statements
12. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
トランザクション ユースケース
あくまでも分析⽤用 (YES)
• レポート処理理のデータがたまに更更新するぐらい
• マスタ変更更、ファクト テーブルの訂正
• 低同時実⾏行行の更更新、低TPS
OLTP データベース (NO)
• ⼤大量量同時実⾏行行の⼩小さい更更新
• 数百〜~数千のコネクション
Hive
OLTP Hive
Replication
Analytics Modifications
Hive
High Concurrency
OLTP
13. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Deep Dive: トランザクション
Hiveのトランザクション対応とACID
• Hiveてのネイティブ対応
• フェーズに分けて:
• Phase 1: Hive Streaming Ingest (append)
• Phase 2: INSERT / UPDATE / DELETE Support
• Phase 3: BEGIN / COMMIT / ROLLBACK Txn
[Done]
[Done]
[Next]
Read-
Optimized
ORCFile
Delta File
Merged
Read-
Optimized
ORCFile
1. Original File
Task reads the latest
ORCFile
Task
Read-
Optimized
ORCFile
Task Task
2. Edits Made
Task reads the ORCFile and merges
the delta file with the edits
3. Edits Merged
Task reads the
updated ORCFile
Hive ACID Compactor
periodically merges the delta
files in the background.
14. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
コンパクションを詳しくみる
Read-
Optimized
ORCFile
Delta File
Merged
Read-
Optimized
ORCFile
Read-
Optimized
ORCFile
Delta File
Delta File
Delta File
Minor Compaction
10% local
Major Compaction
10% global
マイナーとメジャーコンパクション
16. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Ranger: ⼀一元化されたセキュリティ管理理
Apache Ranger
• セキュリティ管理理者にダッシュ
ボードを提供
• セキュリティポリシーの管理理を
⼀一元化
• 全てのHadoopスタックを⼀一貫
してカバーする
17. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
権限のポリシーを設定 (Hive)
17
テーブル/カ
ラムのアクセ
スコントロー
ル、柔軟な定
義
グループ/ユー
ザーの権限管理理
18. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
100倍早くなった仕組み
ORC, Tez, CBO, Vectorization
19. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
スピードの必要性
• Stingerイニシアティブ: Hiveパフォーマンスを100倍向上させるための取込
• 2013年年2⽉月から、2014年年4⽉月にかけて⽬目標達成
• 100%Apacheオープンソース
SQL
Engine
Vectorized
SQL
Engine
Columnar
Storage
ORCFile
=
100X
+
+
Distributed
Execu>on
Apache
Tez
20. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
TPC-‐‑‒DS Benchmark at 30 Terabyte Scale
• TPC-‐‑‒DSより 50 のサンプルクエリを 30 terabyte のスケールで実⾏行行
• 平均 52 倍の速度度アップ, 最⼤大 160 倍の速度度アップ
• ベンチマークの総実⾏行行時間が 7.8 ⽇日 から 9.3 時間に短縮
• Hive 14に追加された Cost-‐‑‒Based Optimizer が更更に 2.5倍の速度度アップ実現
21. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
ORC ファイル フォーマット
Columnar Storage for Hive
22. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
ORCFile – Hiveのためのカラム型ストレージ
• カラム別にデータを格納
• データ型認識識
– データ型固有のエンコーダを使⽤用
– 統計情報も格納(min, max, sum, count)
• 軽量量なインデックスつき
– 関係のない⾏行行をスキップ
Page 22
23. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
ORCFile – ファイルフォーマット
Map/reduce的な処
理理に都合のいい⼤大き
いブロックサイズ
カラム型フォーマッ
トは⾼高い圧縮と⾼高性
能を実現
24. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
ORCFile – テーブル定義の例例
• テーブルまたはパーティション別に定義
• 選べられる圧縮コーデック
Page 24
create table Addresses (
name string,
street string,
city string,
state string,
zip int
) stored as orc tblproperties ("orc.compress"=”ZLIB");
25. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
ORCFile – テキストからORCに変換
• ORCを使わない理理由はない
• SQL 1つでテキストからORCに変換
Page 25
-- Create Text & ORC tables
CREATE TABLE test_details_txt( visit_id INT, store_id SMALLINT) STORED AS TEXTFILE;
CREATE TABLE test_details_orc( visit_id INT, store_id SMALLINT) STORED AS ORC;
-- Load into Text table
LOAD DATA LOCAL INPATH '/home/user/test_details.csv' INTO TABLE test_details_txt;
-- Copy to ORC table
INSERT OVERWRITE INTO test_details_orc SELECT * FROM test_details_txt;
27. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
I/O Synchronization
Barrier
I/O Synchronization
Barrier
Job 1 ( Join a & b )
Job 3 ( Group by of c )
Job 2 (Group by of a
Join b)
Job 4 (Join of S & R )
Hive - MR
MR vs. Tezの例例
Page 27
Single Job
Hive - Tez
Join a & b
Group by of a Join b
Group by of c
Job 4 (Join of S & R )
28. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
Tez – ご紹介
Page 28
• データ処理理アプリのための汎⽤用分散処理理エ
ンジン
– アプリ(フレームワーク)向け、エンドユーザー
向けではない
– Hive on Tez, Pig on Tez, Cascading on Tez, …
• MapReduceの教訓を活かした結果
– ⼤大幅なパフォーマンス改善
– バッチ、インタラクティブ
– Petabytesスケール
• YARNの上で動かす
– クラスタリソースの活⽤用
29. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
Tez – MapReduceからの切切替
• コマンド1つでMapReduceからTezに切切替
Page 29
set hive.execution.engine=tez;
SELECT * FROM my_table;
• Hadoop 2なら、デフォルトをTezにしましょう
$ vi hive-site.xml
hive.execution.engine=tez
30. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Cost Based Optimizer
Making the SQL smarter
31. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
実⾏行行プラン – Cost Based Optimizer in Hive
Cost-‐‑‒Based Optimizer (CBO) はHiveテーブルの統計情報を使って最適な実
⾏行行プランを作成
なぜ cost-‐‑‒based optimization?
• 利利⽤用は簡単 – 例例えば、Joinの順番を⾃自動調整してくれる
• SQLチューニングの必要性を削減
• 効率率率な実⾏行行プランはクラスタの有効利利⽤用に繋がる
Page 31
32. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Star Schema
FACT TABLE
Dimension
Table
Dimension
Table
Dimension
Table
Dimension
Table
33. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
CBO on Selected Queries -‐‑‒ 17
store_sales store_returns catalog_sales
items store
date_dim d1 date_dim d2 date_dim d3
Filter: quarterFilter: quarterFilter: quarter
Filter: dateFilter: dateFilter: date
customer_sk
ticket_number
customer_sk
Item_sk
date_sk date_sk date_sk
item_sk store_sk
34. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
OLD: Left Deep Plan
Reducer 3
• Merge join 2 & 10
• Map join 1
• Map join 6
• Map Join 7
• Map Join 8 store
• Map Join 11 item
• Filter
• Group By
• Reduce
Map 12
Table_scan
Store_returns
Map 6 Table_scan d2, filter
Map 7 Table_scan d3, filter
Reducer 4
Group_By
Reduce
Reducer 10
Merge join 12, 9
Map 9
Table_scan
store_sales
Map 1 Table_scan d1, filter
Map 2 Table_scan catalog_sales
Reducer 5
Limit
B
B
B
Map 11 Table_scan item
Map 8 Table_scan store B
Large Fact tables
joined together
without filters
B
35. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
NEW: Complex Bushy Plan
Reducer 4
Merge join 3 & 8
Map join store
Map join item
Reduce
Map 10
table_scan
store
Map 12
Table_scan
item
Map 3
Store_sales
Map join
Map 8
Store_returns
Map join
Reducer 5
Merge_Join
Group_By
Reduce
Map 11
catalog_sales,
Map Join
Map 9
Table_scan d1,
filter
Map 1
Table_scan d1,
filter
Map 2
Table_scan d1,
filter
Reducer 6
Group by
Reduce
Reducer7
Limit
B
B B
B B
All 3 Large Fact
tables joined with
date dimension
limiting data to
few quarters
36. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
パフォーマンス改善 – Query 17
Scale = 30TB
Input records ~1億8600万
CBO Elapsed
Time (sec)
Elapsed
Time
Intermediate
data (GB)
Output and
Intermediate
Records
OFF 10,683 ~3 hrs 5,017 135,647,792,123
ON 1,284 ~20 mins 275 8,543,232,360
37. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
CBO – 有効にする
• クエリを実⾏行行前にCBOを有効に
Page 37
set hive.cbo.enable=true;
set hive.compute.query.using.stats=true;
set hive.stats.fetch.column.stats=true;
set hive.stats.fetch.partition.stats=true;
• 統計情報を更更新
ANALYZE TABLE my_table COMPUTE STATISTICS FOR COLUMNS;
38. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Vectorized Query Execution
Process 1024 Rows at a Time
39. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
Vectorization – ベクターSQLエンジン
• 機能:
– 1⾏行行づつの代わりに、⼀一回に1024⾏行行を処理理
– モーデンなハードウェア アーキテクチャの活⽤用
• 利利点:
– ⼤大きいクエリは最⼤大3倍早い
– CPU使⽤用時間を削減、クラスタリソースの有効利利⽤用
Page 39
40. © Hortonworks Inc. 2011 – 2015. All Rights Reserved © Hortonworks Inc. 2015
Vectorization – 有効にする
• ベクターSQLエンジンを有効に
Page 40
set hive.vectorized.execution.enabled = true
set hive.vectorized.execution.reduce.enabled = true;
• ORCのみサポート
• ⼀一部サポートしていないデータタイプや機能がある
41. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Hiveの今: まとめ
Hiveは早いバッチやインタラクティブSQLをすでに実現できている
ただ、ユーザーは速度度をもっと早くなってほしい
Petebyteスケールの実績
Scale
i
Hadoop上の最も完成度度
⾼高いなオープンソースの
SQL。
SQL
i
90 以上のHortonworks
お客様が早いSQLのため
Hive-‐‑‒on-‐‑‒Tez をご利利⽤用
Speed
i
Hortonworks
Customer
Support
metrics
as
of
Feb/2015
42. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
1秒以下のレスポンスを実現していく
Solving Hiveʼ’s Top Performance Challenges
43. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
次へ: Stinger.next and Sub-‐‑‒Second SQL
LLAPやHBaseをメタストアにすることで1秒以下のレスポンスを実現
44. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Apache
Hive:
Modern
Architecture
Storage
Columnar
Storage
ORCFile
Parquet
Unstructured
Data
JSON
CSV
Text
Avro
Custom
Weblog
Engine
SQL
Engines
Row
Engine
Vector
Engine
SQL
SQL
Support
SQL:2011
Op>mizer
HCatalog
HiveServer2
Cache
Block
Cache
Linux
Cache
Distributed
Execu>on
Hadoop
1
MapReduce
Hadoop
2
Tez
Historical
Current
In
Development
Legend
45. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Apache
Hive:
Modern
Architecture
Storage
Columnar
Storage
ORCFile
Parquet
Unstructured
Data
JSON
CSV
Text
Avro
Custom
Weblog
Engine
SQL
Engines
Row
Engine
Vector
Engine
SQL
SQL
Support
SQL:2011
Op>mizer
HCatalog
HiveServer2
Cache
Block
Cache
Linux
Cache
Distributed
Execu>on
Hadoop
1
MapReduce
Hadoop
2
Tez
Vector
Cache
LLAP
Persistent
Server
Historical
Current
In
Development
Legend
46. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
HBase メタストア: なぜ?
Page 46Hive & HBase For Transaction Processing
実⾏行行プラン作成のた
め、700以上のメ
タストア問合せ!!
47. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
LLAPとは?
Page 47
Node
LLAP
Process
HDFS
Query
Fragment
LLAP In-Memory
columnar cache
LLAP process
running read task
for a query
LLAPプロセスは複数のノードに常時稼働、Tezタスクを加
速させる
Node
Hive
Query
Node NodeNode Node
LLAP LLAP LLAP LLAP
LLAP = Live Long And Process
48. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
LLAP: メリット
Page 48
• LLAP はノード上に常時稼働
– 起動オーバーヘッドをなくす
• LLAPはカラムデータをインメモリにキャッシュ
– ホッとデータはHDFSに⾏行行かなくで済む
– カラム型でキャッシュ:直接ベクターSQLエンジン
に処理理させる
• YARNを使ったリソース管理理
– クラスタリソースの活⽤用
Node
LLAP Process
Query
Fragment
LLAP In-
Memory
columnar
cache
LLAP
process
running a
task for a
query
HDFS
49. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Hiveの1秒以下レスポンス
=
Sub-‐Second
Hive
Metadata
Fast,
Scalable
Metadata
Catalog
Persistent
Server
LLAP
+
+
SQL
Engine
Vectorized
Hash
Join
Choice
of
Execu>on
Engines
Tez
+
51. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Hiveの今とこれから
• HiveはSQL on Hadoopの標準
• バッチから、インタラクティブ処理理まで1つのSQLツールで
• ETL、レポート、分析あらゆるSQLユースケースをHiveで
• これからもHiveは進化していく
• SQL:2011 Analytics標準対応
• トランザクション強化
• 1秒以下のクエリレスポンス
52. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
今すぐHiveを
• 今すぐHiveの最新機能を使いましょう
• Hive on Tez
• ORCファイル
• CBOを有効に
• ベクターSQLエンジン
• ただ数⾏行行の設定変更更/SQLですぐ利利⽤用できます
• これからのHive進化を楽しみに
53. © Hortonworks Inc. 2011 – 2015. All Rights Reserved
Thank you
Yifeng Jiang, Solutions Engineer, Hortonworks
@uprush