本文共 5409 字,大约阅读时间需要 18 分钟。
- Pressto时一个开源的分布式SQL查询引擎,数据量支持GB到PB字节,主要用来处理秒级查询的场景
- 虽然Pressto可以解析SSQL,但它不是一个标准的数据库,不是MySQL、Oracle的代替品,也不能用来出来在线事务(OLTP)
- Coordinator:决策者 -> 解析成MR
- Worker:工作者 -> 跑任务
- Connector:不同的数据源 不用的Connector
- Catalog:一个数据源叫做Catalog
- 基于内存
- 跨数据源联表查询(支持Hive join MySQL的联表查询等)
- 缺点:对于连表查询,可能产生大量的临时i数据,因此速度会变慢
具体比较:https://blog.csdn.net/u012551524/article/details/79124532
测试结论:Impala性能稍领先于Presto,但是Presto在数据源支持上非常丰富,包括Hive、图数据库、传统关系型数据库、Redis等。
官网地址:https://prestodb.github.io/
下载地址:https://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.196/presto-server-0.196.tar.gz
tar -zxvf presto-server-0.196.tar.gz -C /opt/module/
进入到/opt/module/presto目录,并创建存储数据文件夹
mkdir data
进入到/opt/module/presto目录,并创建存储配置文件文件夹
mkdir etc
配置在/opt/module/presto/etc目录下添加jvm.config配置文件
vim jvm.config-server-Xmx16G-XX:+UseG1GC-XX:G1HeapRegionSize=32M-XX:+UseGCOverheadLimit-XX:+ExplicitGCInvokesConcurrent-XX:+HeapDumpOnOutOfMemoryError-XX:+ExitOnOutOfMemoryError
Presto可以支持多个数据源,在Presto里面叫catalog,这里我们配置支持Hive的数据源,配置一个Hive的catalog
[atguigu@hadoop102 etc]$ mkdir catalog[atguigu@hadoop102 catalog]$ vim hive.properties connector.name=hive-hadoop2hive.metastore.uri=thrift://hadoop102:9083
xsync /opt/module/presto-server-0.196/
分发之后,分别进入hadoop102、hadoop103、hadoop104三台主机的/opt/module/presto/etc的路径。配置node属性,node id每个节点都不一样。
[atguigu@hadoop102 etc]$vim node.propertiesnode.environment=productionnode.id=ffffffff-ffff-ffff-ffff-ffffffffffffnode.data-dir=/opt/module/presto-server-0.196/data[atguigu@hadoop103 etc]$vim node.propertiesnode.environment=productionnode.id=ffffffff-ffff-ffff-ffff-fffffffffffenode.data-dir=/opt/module/presto/data[atguigu@hadoop104 etc]$vim node.propertiesnode.environment=productionnode.id=ffffffff-ffff-ffff-ffff-fffffffffffdnode.data-dir=/opt/module/presto-server-0.196/data
Presto是由一个coordinator节点和多个worker节点组成。在hadoop102上配置成coordinator,在hadoop103、hadoop104上配置为worker。
hadoop102
[atguigu@hadoop102 etc]$ vim config.propertiescoordinator=truenode-scheduler.include-coordinator=falsehttp-server.http.port=8881query.max-memory=50GBdiscovery-server.enabled=truediscovery.uri=http://hadoop102:8881
hadoop103 和hadoop104
[atguigu@hadoop103 etc]$ vim config.propertiescoordinator=falsehttp-server.http.port=8881query.max-memory=50GBdiscovery.uri=http://hadoop102:8881
- 在hadoop102的/opt/module/hive目录下,启动Hive Metastore,用atguigu角色
[atguigu@hadoop102 hive]$nohup bin/hive --service metastore >/dev/null 2>&1 &
分别在hadoop102、hadoop103、hadoop104上启动Presto Server
前台启动:[atguigu@hadoop102 presto-server-0.196]$ bin/launcher run后台启动:bin/launcher start
下载Presto的客户端
https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/0.196/presto-cli-0.196-executable.jar
将presto-cli-0.196-executable.jar上传到hadoop102的/opt/module/presto文件夹下
mv presto-cli-0.196-executable.jar prestocli
chmod 777 prestocli
-> ./prestocli --server hadoop102:8881 --catalog hive --schema default
Presto的命令行操作,相当于Hive命令行操作。每个表必须要加上schema(关系数据库里面的databses概念)。
show schemas;use gmall;select * from gmall.ods_sku_info limit 100;
将yanagishima-18.0.zip上传到hadoop102的/opt/module目录
unzip yanagishima-18.0.zip
进入到/opt/module/yanagishima-18.0/conf文件夹,编写yanagishima.properties配置
jetty.port=7080presto.datasources=atguigu-prestopresto.coordinator.server.atguigu-presto=http://hadoop102:8881catalog.atguigu-presto=hiveschema.atguigu-presto=defaultsql.query.engines=presto
在/opt/module/yanagishima-18.0路径下启动yanagishima
nohup bin/yanagishima-start.sh >y.log 2>&1 &
启动web页面:http://hadoop102:7080
select * from hive.gmall.ads_back_count limit 100
与Hive类似,Presto会根据元数据信息读取分区数据,合理的分区能减少Presto数据读取量,提升查询性能。
Presto对ORC文件读取做了特定优化,因此在Hive中创建Presto使用的表时,建议采用ORC格式存储。相对于Parquet,Presto对ORC支持更好。
数据压缩可以减少节点间数据传输对IO带宽压力,对于即席查询需要快速解压,建议采用Snappy压缩。
由于采用列式存储,选择需要的字段可加快字段的读取、减少数据量。避免采用*读取所有字段。
对于有分区的表,where语句中优先使用分区字段进行过滤。acct_day是分区字段,visit_time是具体访问时间。
[GOOD]: SELECT time, user, host FROM tbl where acct_day=20171101[BAD]: SELECT * FROM tbl where visit_time=20171101
合理安排Group by语句中字段顺序对性能有一定提升。将Group By语句中字段按照每个字段distinct数据多少进行降序排列。
[GOOD]: SELECT GROUP BY uid, gender[BAD]: SELECT GROUP BY gender, uid
Order by需要扫描数据到单个worker节点进行排序,导致单个worker需要大量内存。如果是查询Top N或者Bottom N,使用limit可减少排序计算和内存压力。
[GOOD]: SELECT * FROM tbl ORDER BY time LIMIT 100[BAD]: SELECT * FROM tbl ORDER BY time
Presto中join的默认算法是broadcast join,即将join左边的表分割到多个worker,然后将join右边的表数据整个复制一份发送到每个worker进行计算。如果右边的表数据量太大,则可能会报内存溢出错误。
[GOOD] SELECT ... FROM large_table l join small_table s on l.id = s.id[BAD] SELECT ... FROM small_table s join large_table l on l.id = s.id
避免和关键字冲突:MySQL对字段加反引号`、Presto对字段加双引号分割
当然,如果字段名称不是关键字,可以不加这个双引号。
对于Timestamp,需要进行比较的时候,需要添加Timestamp关键字,而MySQL中对Timestamp可以直接进行比较。
/*MySQL的写法*/SELECT t FROM a WHERE t > '2017-01-01 00:00:00'; /*Presto中的写法*/SELECT t FROM a WHERE t > timestamp '2017-01-01 00:00:00';
Presto中不支持insert overwrite语法,只能先delete,然后insert into。
Presto目前支持Parquet格式,支持查询,但不支持insert。
原谅敌人要比原谅朋友容易。——狄尔治夫人