Facebook presto是什么,继Facebook建立了HIVE神器后的又一以SQL语言做为接口的分布式实时查询引擎,能够对PB级的数据进行快速的交互式查询。它支持标准的ANSI SQL.包含查询,聚合,JOIN以及窗口函数等。除了Facebook这个创造都在使用外,国内像京东,美团等也都有普遍的使用。对于英文很差的同窗能够访问由京东建立的这个中文翻译站点:http://prestodb-china.com/,只是这个版本才0.100,如今最新版已到0.156.node
Presto是一个开源的分布式SQL查询引擎,适用于交互式分析查询,数据量支持GB到PB字节。sql
Presto的设计和编写彻底是为了解决像Facebook这样规模的商业数据仓库的交互式分析和处理速度的问题。shell
Presto支持在线数据查询,包括Hive, Cassandra, 关系数据库以及专有数据存储。 一条Presto查询能够将多个数据源的数据进行合并,能够跨越整个组织进行分析。数据库
Presto以分析师的需求做为目标,他们指望响应时间小于1秒到几分钟。 Presto终结了数据分析的两难选择,要么使用速度快的昂贵的商业方案,要么使用消耗大量硬件的慢速的“免费”方案。json
Facebook使用Presto进行交互式查询,用于多个内部数据存储,包括300PB的数据仓库。 天天有1000多名Facebook员工使用Presto,执行查询次数超过30000次,扫描数据总量超过1PB。安全
领先的互联网公司包括Airbnb和Dropbox都在使用Presto。ruby
Presto一样是须要部署到每个DataNode上的分布式系统,它包括一个coordinator和多个worker: 服务器
值得一提的是Presto以插件形式对数据存储层进行了抽象,它叫作链接器,如:Cassandra Connector,Hive Connector,MySQL Connector等,能够看出它不只默认提供了Hadoop相关组件的链接器,还提供了Mysql, Postgresql等RDBMS的链接器,同时也能够方便的经过自定义链接器开发,达到适用于不一样数据存储层的扩展目的。markdown
Presto提供如下几种类型的使用接口:jvm
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
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数据存储目录,放在了解压软件目录下
3. 配置jvm.config
jvm.config这个配置文件经过名字,你们应该知道是配置什么了吧。内容以下:
-server -Xmx8G -XX:+UseG1GC -XX:G1HeapRegionSize=32M -XX:+UseGCOverheadLimit -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError=kill -9 %p
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
Worker节点配置:
coordinator=false http-server.http.port=8089 query.max-memory=50GB query.max-memory-per-node=1GB discovery.uri=http://master:8089
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
6. 启动Presto
通过这么多的配置,终于能够到了启动Presto这一步,这一步就简单了,直接在每个节点上执行启动命令便可:
bin/launcher start
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]
system链接器是Presto自带的链接器,不须要配置。包含Presto的节点信息,配置信息以及metrics信息等。
1. 使用命令行链接到Presto,并指定使用HIVE链接器:
./presto-cli-0.107-jd-executable.jar --server master:8089 --catalog hive --schema default #指定默认链接到HIVE的default数据库
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]
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
Facebook presto虽然发展时间不长,版本也还不高,但当前版本在功能上已比较丰富,并且在查询效率上已达到了近乎实时的要求,且很是灵活。Presto将会成为实时查询工具上的一个重要选择。
转:http://blog.csdn.net/hezh914/article/details/53097853