1. Presto 是什么
Facebook presto是什么,繼Facebook創建了HIVE神器后的又一以SQL語言作為接口的分布式實時查詢引擎,可以對PB級的數據進行快速的交互式查詢。它支持標准的ANSI SQL.包含查詢,聚合,JOIN以及窗口函數等。除了Facebook這個創造都在使用外,國內像京東,美團等也都有廣泛的使用。對於英文不好的同學可以訪問由京東創建的這個中文翻譯站點:http://prestodb-china.com/,只是這個版本才0.100,現在最新版已到0.156.
Presto是一個開源的分布式SQL查詢引擎,適用於交互式分析查詢,數據量支持GB到PB字節。
Presto的設計和編寫完全是為了解決像Facebook這樣規模的商業數據倉庫的交互式分析和處理速度的問題。
它可以做什么?
Presto支持在線數據查詢,包括Hive, Cassandra, 關系數據庫以及專有數據存儲。 一條Presto查詢可以將多個數據源的數據進行合並,可以跨越整個組織進行分析。
Presto以分析師的需求作為目標,他們期望響應時間小於1秒到幾分鍾。 Presto終結了數據分析的兩難選擇,要么使用速度快的昂貴的商業方案,要么使用消耗大量硬件的慢速的“免費”方案。
誰在使用它?
Facebook使用Presto進行交互式查詢,用於多個內部數據存儲,包括300PB的數據倉庫。 每天有1000多名Facebook員工使用Presto,執行查詢次數超過30000次,掃描數據總量超過1PB。
領先的互聯網公司包括Airbnb和Dropbox都在使用Presto。
2. Presto 結構
Presto同樣是需要部署到每一個DataNode上的分布式系統,它包括一個coordinator和多個worker:
- Coordinator: 接入接口,解析SQL語句,生成查詢計划,任務分發等。
- Worker:負責與數據的讀寫交互以及執行查詢計划
值得一提的是Presto以插件形式對數據存儲層進行了抽象,它叫做連接器,如:Cassandra Connector,Hive Connector,MySQL Connector等,可以看出它不僅默認提供了Hadoop相關組件的連接器,還提供了Mysql, Postgresql等RDBMS的連接器,同時也可以方便的通過自定義連接器開發,達到適用於不同數據存儲層的擴展目的。
Presto提供以下幾種類型的使用接口:
- Presto命令行
- JDBC驅動
3. Presto安裝
Presto只支持Linux系統的部署。它的Worker節點同時也可以作為Coordinator節點,但是Presto建議獨立部署Coordinator節點,並采用獨立服務器進行部署,避免性能影響。
本文的測試環境為基於CDH 5.5的Hadoop集群環境的安裝和測試。Presto 版本:0.152.3. Presto 的安裝JDK版本必須要求:1.8. 安全方式為獨立Coordinator節點+Worker節點的方式
1. 解壓Presto到每一台Worker節點和Coordinator節點
tar -xzvf presto-server-0.152.3.tar.gz
- 1
2. 配置node.properties
node.properties包含了Presto的節點配置信息,在解壓后目錄的 etc/node.properties位置。,如:
node.environment=myprestoproduction #全部相同的集群名字,經測試不能大小寫混合 node.id=ffffffff-ffff-ffff-ffff-fffffffffff1 #這個每個presto節點ID都需要不一樣,可在后面數字遞增 node.data-dir=/usr/local/presto-server-0.152.3/data #presto數據存儲目錄,放在了解壓軟件目錄下
- 1
- 2
- 3
3. 配置jvm.config
jvm.config這個配置文件通過名字,大家應該知道是配置什么了吧。內容如下:
-server -Xmx8G -XX:+UseG1GC -XX:G1HeapRegionSize=32M -XX:+UseGCOverheadLimit -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError=kill -9 %p
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
4. Presto配置:config.properties
config.properties配置文件用於配置Presto的運行參數,這里Coordinator與Workder節點需要分開配置不同的內容。
Coordinator節點配置:
coordinator=true #這里指定作為coordinator節點運行 node-scheduler.include-coordinator=false http-server.http.port=8089 query.max-memory=50GB #單個查詢可用的總內存 query.max-memory-per-node=1GB #單個查詢單個節點的可用最大內存 discovery-server.enabled=true #Discovery服務用於Presto集群的節點狀態服務 discovery.uri=http://master:8089
- 1
- 2
- 3
- 4
- 5
- 6
- 7
Worker節點配置:
coordinator=false http-server.http.port=8089 query.max-memory=50GB query.max-memory-per-node=1GB discovery.uri=http://master:8089
- 1
- 2
- 3
- 4
- 5
- 至此就可以正常啟動Presto了。但是沒有配置任何Connector的Presto也只能拿來看一看了,所以下面還是先把Hive Connector配置好。
5. 預先配置好Hive Connector
新建好文件: etc/catalog/hive.properties,內容為:
connector.name=hive-cdh5 # 根據Hadoop版本情況,值可以是: hive-hadoop1, hive-hadoop2,hive-cdh4,hive-cdh5 hive.metastore.uri=thrift://master:9083 # hive的MetaStore服務URL hive.config.resources=/etc/hadoop/conf/core-site.xml,/etc/hadoop/conf/hdfs-site.xml
- 1
- 2
- 3
6. 啟動Presto
經過這么多的配置,終於可以到了啟動Presto這一步,這一步就簡單了,直接在每一個節點上執行啟動命令即可:
bin/launcher start
- 1
- 值得注意的是, CDH安裝的JDK版本為1.7,而Presto要求的版本是1.8.因此需要更改launcher文件,在前面增加JAVA環境變量設置,覆蓋默認的1.7設置。
7. 連接到Presto
使用命令行連接到Presto:
可是怎會如此輕松就能讓你連上去,你得下載一個文件:presto-cli-0.156-executable.jar,然后重命名為presto,並增加可執行權限(chmod +x),后可以執行連接命令:
./presto --server master:8089 presto:default> SELECT * FROM system.runtime.nodes; node_id | http_uri | node_version | coordinator | state --------------------------------------+---------------------------+--------------+-------------+-------- ffffffff-ffff-ffff-ffff-fffffffffff2 | http://192.168.5.202:8089 | 0.152.3 | false | active ffffffff-ffff-ffff-ffff-fffffffffff1 | http://192.168.5.200:8089 | 0.152.3 | true | active ffffffff-ffff-ffff-ffff-fffffffffff3 | http://192.168.5.203:8089 | 0.152.3 | false | active ffffffff-ffff-ffff-ffff-fffffffffff4 | http://192.168.5.204:8089 | 0.152.3 | false | active (4 rows) Query 20161108_101627_00016_3i6da, FINISHED, 2 nodes Splits: 2 total, 2 done (100.00%) 0:00 [4 rows, 300B] [9 rows/s, 727B/s]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
system連接器是Presto自帶的連接器,不需要配置。包含Presto的節點信息,配置信息以及metrics信息等。
5. 使用Presto查詢HIVE表數據
1. 使用命令行連接到Presto,並指定使用HIVE連接器:
./presto-cli-0.107-jd-executable.jar --server master:8089 --catalog hive --schema default #指定默認連接到HIVE的default數據庫
- 1
- 2
2. 查詢HIVE表數據,接下來就可以使用標准SQL查詢HIVE數據,如:
presto:default> desc sample_08;
Column | Type | Comment -------------+---------+--------- code | varchar | description | varchar | total_emp | integer | salary | integer | (4 rows) Query 20161108_145619_00028_3i6da, FINISHED, 2 nodes Splits: 2 total, 2 done (100.00%) 0:00 [4 rows, 258B] [11 rows/s, 726B/s] presto:default> select * from sample_08 limit 3; code | description | total_emp | salary ---------+------------------------+-----------+-------- 00-0000 | All Occupations | 135185230 | 42270 11-0000 | Management occupations | 6152650 | 100310 11-1011 | Chief executives | 301930 | 160440 (3 rows) Query 20161108_145632_00029_3i6da, FINISHED, 2 nodes Splits: 2 total, 2 done (100.00%) 0:02 [823 rows, 45KB] [439 rows/s, 24KB/s]
- 12
- 13
- 14
6. 問題
1. 在使用Presto查詢Parquet格式中的Decimal數據類型時會出現異常,需要手動轉換:
presto:default> desc test_decimal; Column | Type | Comment ----------+---------------+--------- dec_col | decimal(2,0) | (1 rows) Query 20161108_151431_00066_3i6da, FINISHED, 2 nodes Splits: 2 total, 2 done (100.00%) 0:00 [5 rows, 358B] [14 rows/s, 1.02KB/s] presto:default> select dec_col from test_decimal limit 1; Query is gone (server restarted?) #這兒產生異常了 presto:default> select cast(dec_col as integer) from test_decimal limit 1; _col0 ------- 1 (1 row) Query 20161108_151456_00068_3i6da, FINISHED, 1 node Splits: 2 total, 2 done (100.00%) 0:00 [7.28K rows, 118KB] [19.5K rows/s, 314KB/s]
2. 另外一個就是Presto的異常信息太簡結了,很多都是Query is gone,很不好排查,如:
presto:default> explain select * from sample_08; Query is gone (server restarted?)
3. 兼容性問題,比如:
presto:default> select * from sample_tabpart limit 10; Query 20161109_031436_00013_3i6da failed: Unsupported Hive type char(4) found in partition keys of table default.sample_tabpart # 不支持以CHAR為類型的分區KEY
7. 最后
Facebook presto雖然發展時間不長,版本也還不高,但當前版本在功能上已比較豐富,而且在查詢效率上已達到了近乎實時的要求,且非常靈活。Presto將會成為實時查詢工具上的一個重要選擇。
轉:http://blog.csdn.net/hezh914/article/details/53097853