1.1 Presto简介

1.1.1 Presto概念

 Presto是一个开源的分布式SQL查询引擎,数据量支持GB到PB字节,主要用来处理秒级查询的场景。

注意:虽然Presto可以解析SQL,但是他不是一个标准的数据库。不是MySQL,Oracle的替代品,也不能用来处理在线事务OLTP。

1.1.2 Presto架构

 

1.1.3 Presto优缺点

 

 

 

1.1.4 PrestoImpala性能比较

https://blog.csdn.net/u012551524/article/details/79124532

测试结论Impala性能稍领先于Presto,但是Presto在数据源支持上非常丰富,包括Hive、图数据库、传统关系型数据库、Redis等。

1.2 Presto安装

1.2.1 Presto Server安装

0官网地址

https://prestodb.github.io/

1下载地址

https://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.196/presto-server-0.196.tar.gz

2)将presto-server-0.196.tar.gz导入hadoop102的/opt/software目录,并解压到/opt/module目录

[atguigu@hadoop102 software]$ tar -zxvf presto-server-0.196.tar.gz -C /opt/module/

3)修改名称为presto

[atguigu@hadoop102 module]$ mv presto-server-0.196/ presto

4)进入/opt/module/presto目录,并创建存储数据文件夹

[atguigu@hadoop102 presto]$ mkdir data

5)进入/opt/module/presto目录,并创建存储配置文件文件夹

[atguigu@hadoop102 presto]$ mkdir etc

6)配置在/opt/module/presto/etc目录添加jvm.config配置文件

[atguigu@hadoop102 etc]$ vim jvm.config

添加如下内容

-server

-Xmx16G

-XX:+UseG1GC

-XX:G1HeapRegionSize=32M

-XX:+UseGCOverheadLimit

-XX:+ExplicitGCInvokesConcurrent

-XX:+HeapDumpOnOutOfMemoryError

-XX:+ExitOnOutOfMemoryError

7)Presto可以支持多个数据源,在Presto里面叫catalog,这里我们配置支持Hive的数据源,配置一个Hivecatalog

[atguigu@hadoop102 etc]$ mkdir catalog

[atguigu@hadoop102 catalog]$ vim hive.properties 

添加如下内容

connector.name=hive-hadoop2

hive.metastore.uri=thrift://hadoop102:9083

8)将hadoop102上presto分发到hadoop103、hadoop104

[atguigu@hadoop102 module]$ xsync presto

9)分发之后,分别进入hadoop102、hadoop103、hadoop104三台主机的/opt/module/presto/etc的路径。配置node属性,node id每个节点都不一样

[atguigu@hadoop102 etc]$vim node.properties

node.environment=production

node.id=ffffffff-ffff-ffff-ffff-ffffffffffff

node.data-dir=/opt/module/presto/data

 

[atguigu@hadoop103 etc]$vim node.properties

node.environment=production

node.id=ffffffff-ffff-ffff-ffff-fffffffffffe

node.data-dir=/opt/module/presto/data

 

[atguigu@hadoop104 etc]$vim node.properties

node.environment=production

node.id=ffffffff-ffff-ffff-ffff-fffffffffffd

node.data-dir=/opt/module/presto/data

10Presto是由一个coordinator节点和多个worker节点组成。在hadoop102上配置成coordinator,hadoop103、hadoop104上配置为worker。

1hadoop102上配置coordinator节点

[atguigu@hadoop102 etc]$ vim config.properties

添加内容如下

coordinator=true

node-scheduler.include-coordinator=false

http-server.http.port=8881

query.max-memory=50GB

discovery-server.enabled=true

discovery.uri=http://hadoop102:8881

2hadoop103、hadoop104上配置worker节点

[atguigu@hadoop103 etc]$ vim config.properties

添加内容如下

coordinator=false

http-server.http.port=8881

query.max-memory=50GB

discovery.uri=http://hadoop102:8881

 

[atguigu@hadoop104 etc]$ vim config.properties

添加内容如下

coordinator=false

http-server.http.port=8881

query.max-memory=50GB

discovery.uri=http://hadoop102:8881

11)在hadoop102的/opt/module/hive目录下,启动Hive Metastore,用atguigu角色

[atguigu@hadoop102 hive]$

nohup bin/hive --service metastore >/dev/null 2>&1 &

12)分别hadoop102、hadoop103、hadoop104上启动Presto Server

1前台启动Presto,控制台显示日志

[atguigu@hadoop102 presto]$ bin/launcher run

[atguigu@hadoop103 presto]$ bin/launcher run

[atguigu@hadoop104 presto]$ bin/launcher run

2后台启动Presto

[atguigu@hadoop102 presto]$ bin/launcher start

[atguigu@hadoop103 presto]$ bin/launcher start

[atguigu@hadoop104 presto]$ bin/launcher start

13)日志查看路径/opt/module/presto/data/var/log

1.2.2 Presto命令Client安装

1下载Presto的客户端

https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/0.196/presto-cli-0.196-executable.jar

2)将presto-cli-0.196-executable.jar上传hadoop102/opt/module/presto文件夹下

3)修改文件名称

[atguigu@hadoop102 presto]$ mv presto-cli-0.196-executable.jar  prestocli

4)增加执行权限

[atguigu@hadoop102 presto]$ chmod +x prestocli

5)启动prestocli

[atguigu@hadoop102 presto]$ ./prestocli --server hadoop102:8881 --catalog hive --schema default

6Presto命令行操作

Presto的命令行操作,相当于Hive命令行操作。每个表必须要加上schema

例如:

select * from schema.table limit 100

1.2.3 Presto可视化Client安装

1)将yanagishima-18.0.zip上传hadoop102/opt/module目录

2解压缩yanagishima

[atguigu@hadoop102 module]$ unzip yanagishima-18.0.zip

cd yanagishima-18.0

3)进入/opt/module/yanagishima-18.0/conf文件,编写yanagishima.properties配置

[atguigu@hadoop102 conf]$ vim yanagishima.properties

添加如下内容

jetty.port=7080

presto.datasources=atiguigu-presto

presto.coordinator.server.atiguigu-presto=http://hadoop102:8881

catalog.atiguigu-presto=hive

schema.atiguigu-presto=default

sql.query.engines=presto

4)在/opt/module/yanagishima-18.0路径启动yanagishima

[atguigu@hadoop102 yanagishima-18.0]$

nohup bin/yanagishima-start.sh >y.log 2>&1 &

5)启动web页面

http://hadoop102:7080

看到界面,进行查询了。

6)查看表结构

 

这里有个Tree View,可以查看所有表的结构,包括Schema、表、字段等。

比如执行select * from hive.dw_weather.tmp_news_click limit 10,这个句子里Hive这个词可以删掉,是上面配置的Catalog

 

每个表后面都有个复制键,点一下会复制完整的表名,然后再上面框里面输入sql语句,ctrl+enter键执行显示结果

 

 

 

1.3 Presto优化之数据存储

1.3.1 合理设置分区

Hive类似,Presto会根据元数据信息读取分区数据,合理的分区能减少Presto数据读取量,提升查询性能。

1.3.2 使用列式存储

PrestoORC文件读取做了特定优化,因此在Hive中创建Presto使用的表时,建议采用ORC格式存储。相对于ParquetPrestoORC支持更好。

1.3.3 使用压缩

数据压缩可以减少节点间数据传输对IO带宽压力,对于即席查询需要快速解压,建议采用Snappy压缩。

1.4 Presto优化之查询SQL

1.4.1 只选择使用的字段

由于采用列式存储,选择需要的字段可加快字段的读取、减少数据量。避免采用*读取所有字段。

[GOOD]: SELECT time, user, host FROM tbl

 

[BAD]:  SELECT * FROM tbl

1.4.2 过滤条件必须加上分区字段

对于有分区的表,where语句中优先使用分区字段进行过滤。acct_day是分区字段,visit_time是具体访问时间。

[GOOD]: SELECT time, user, host FROM tbl where acct_day=20171101

 

[BAD]:  SELECT * FROM tbl where visit_time=20171101

1.4.3 Group By语句优化

合理安排Group by语句中字段顺序对性能有一定提升。将Group By语句中字段按照每个字段distinct数据多少进行降序排列。

[GOOD]: SELECT GROUP BY uid, gender

 

[BAD]:  SELECT GROUP BY gender, uid

1.4.4 Order by时使用Limit

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

1.4.5 使用Join语句时将大表放在左边

Prestojoin的默认算法是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

1.5 注意事项

1.5.1 字段名引用

避免和关键字冲突:MySQL字段加反引号`Presto字段加双引号分割

当然,如果字段名称不是关键字,可以不加这个双引号。

1.5.2 时间函数

对于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';

1.5.3 不支持INSERT OVERWRITE语法

Presto中不支持insert overwrite语法,只能先delete,然后insert into

1.5.4 PARQUET格式

Presto目前支持Parquet格式,支持查询,但不支持insert

posted on 2020-06-03 14:08  大羽治不了水  阅读(1359)  评论(0编辑  收藏  举报