1 tez的概览
1.1 tez介绍
1.1.1 介绍
tez是一个apache的开源项目,意在构建一个应用框架,能通过复杂任务的DAG来处理数据。它是基于当前的hadoop yarn之上,换句话就是yarn为其提供资源。
tez主要的两个设计目标:
增强终端用户使用:
灵活的数据流定义API
灵活的输入输出运行时模型(强调处理模型)
数据类型无关
简洁部署
高性能执行:
通过mapreduce提高性能
资源优化管理
执行时计划重定义
物理数据流的动态决策
tez可以像Apache Hive和Apache Pig这样的项目运行复杂的任务DAG,Tez可以用于处理数据,早期使用了多个MR作业,现在在单个Tez作业中,如下所示:
[外链图片转存失败(img-Iq305CQu-97)(img/04.png)]
注:
天蓝色方块为map,绿色方块为reduce,云状的为输出隐藏,绿色的圆圈为一个mr。
参考官网:http://tez.apache.org/
2 tez的安装
2.1 tez下载
tez提供咯二进制包和源码包,二者官网下载路径: https://mirrors.tuna.tsinghua.edu.cn/apache/tez/0.9.0/ 注: 官方提供咯源码包和二进制包,我这儿就不在下载源码来编译,而是直接使用其二进制包来安装。
2.2 tez源码编译
暂时不下载源码包来编译,费时,可以自行参考官网编译。参考官网编译地址:
http://tez.apache.org/install.html
2.3 tez的安装
2.3.1 解压并配置环境
解压重命名: [root@hadoop01 ~]# tar -zxvf /home/apache-tez-0.9.0-bin.tar.gz -C /usr/local/ [root@hadoop01 ~]# mv /usr/local/apache-tez-0.9.0-bin/ /usr/local/tez-0.9.0/ 上传tez.tar.gz到hdfs中一个目录中: [root@hadoop01 tez-0.9.0]# hdfs dfs -mkdir /tez-0.9.0 [root@hadoop01 tez-0.9.0]# hdfs dfs -put /usr/local/tez-0.9.0/share/tez.tar.gz /tez-0.9.0 配置环境: [root@hadoop01 ~]# vi /etc/profile 增加内容如下: export TEZ_CONF_DIR=$HADOOP_CONF_DIR export TEZ_JARS=/usr/local/tez-0.9.0/*:/usr/local/tez-0.9.0/lib/* export HADOOP_CLASSPATH=$TEZ_CONF_DIR:$TEZ_JARS:$HADOOP_CLASSPATH
然后保存退出,验证环境变量即可。
[root@hadoop01 ~]# source /etc/profile
2.3.2 配置配置文件
在hadoop的配置目录下创建tez-site.xml配置文件,内容如下:
[root@hadoop01 tez-0.9.0]# vi /usr/local/hadoop-2.7.1/etc/hadoop/tez-site.xml 文件中添加如下内容:
tez.lib.uris
${fs.defaultFS}/tez-0.9.0/tez.tar.gz
tez.container.max.java.heap.fraction
0.2
更多配置参考默认配置:/usr/local/tez-0.9.0/conf/tez-default-template.xml
2.4 tez、hadoop、hive整合
2.4.1 tez和hadoop的兼容
tez下的lib目录中的hadoop包的版本和真实安装的hadoop版本不一致,需要将其jar包换成一致. 删除不符合版本的jar: [root@hadoop01 tez-0.9.0]# rm -rf ./lib/hadoop-mapreduce-client-core-2.7.0.jar ./lib/hadoop-mapreduce-client-common-2.7.0.jar 重新再hadoop目录中拷贝: [root@hadoop01 tez-0.9.0]# cp /usr/local/hadoop-2.7.1/share/hadoop/mapreduce/hadoop-mapreduce-client-common-2.7.1.jar /usr/local/hadoop-2.7.1/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.7.1.jar /usr/local/tez-0.9.0/lib/
然后启动hadoop和hive。
2.4.2 tez和hive结合
如果要将hive的执行引擎更换成tez,则只需要设置执行引擎即可。 set hive.execution.engine=tez;
注意:
1、jar包冲突问题。
2、tez引擎不能使用,需要测试判断。
3 tez案例
3.1 tez执行
创建表: create table if not exists tz( name string, age int ) row format delimited fields terminated by '\t' ; create table if not exists tz_par( age int, age_cnt int ) partitioned by(dt string) row format delimited fields terminated by '\t' ; 数据: vi /home/tz zs 16 ls 18 ww 18 goudan 18 mazi 16 加载数据: load data local inpath "/home/tz" into table tz; 执行查询: insert into tz_par partition(dt="2019-08-12") select age, count(*) from tz group by age ; 执行状态和查看结果,如下图:
[外链图片转存失败(img-m09qiJTw-99)(img/02.png)]
3.2 还原mr执行
一般情况下,除非整个项目以tez执行,如果仅仅是一部分,则需要两个执行引擎随时切换。 创建表: create table if not exists tz_par1( age int, age_cnt int ) partitioned by(dt string) row format delimited fields terminated by '\t' ; 执行查询: set hive.execution.engine=tez; insert into tz_par partition(dt="2019-08-12") select age, count(*) from tz group by age ; 查看执进度和结果如下:

到此为止,证明我们的语句真的可以使用tez引擎来计算咯。
4 tez优化
一、AM、Container大小设置
1、tez.am.resource.memory.mb #设置 tez AM容器内存
默认值:1024
配置文件:tez-site.xml
建议:不小于或者等于yarn.scheduler.minimum-allocation-mb值。
2、hive.tez.container.size #设置 tez container内存
默认值:-1
默认情况下,Tez将生成一个mapper大小的容器。这可以用来覆盖默认值。
配置文件:hive-site-xml
建议:不小于或者是yarn.scheduler.minimum-allocation-mb的倍数
二、AM、Container JVM参数设置
1、tez.am.launch.cmd-opts #设置 AM jvm,启动TEZ任务进程期间提供的命令行选项。
默认值:-XX:+PrintGCDetails -verbose:gc -XX:+PrintGCTimeStamps -XX:+UseNUMA -XX:+UseParallelGC(用于GC),默认的大小:80%*tez.am.resource.memory.mb
配置文件:tez-site.xml
建议:不要在这些启动选项中设置任何xmx或xms,以便tez可以自动确定它们。
2、hive.tez.java.ops #设置 container jvm
默认值:Hortonworks建议“–server –Djava.net.preferIPv4Stack=true–XX:NewRatio=8 –XX:+UseNUMA –XX:UseG1G”,默认大小:80%*hive.tez.container.size
说明:在hive 2.x的官方文档中没有找到这个参数。看有些博客里面有这个值。
配置文件:hive-site.xml
3、tez.container.max.java.heap.fraction #设置task/AM占用jvm内存大小的比例。
默认值:0.8
配置文件:tez-site.xml
说明:这个值按具体需要调整,当内存不足时,一般都要调小。
三、Hive内存Map Join参数设置
1、tez.runtime.io.sort.mb #设置输出排序内存大小
默认值:100
配置文件:tez-site.xml
建议:40%*hive.tez.container.size,一般不超过2G
2、hive.auto.convert.join.noconditionaltask #是否将多个mapjoin合并为一个
默认值:true
建议使用默认值。
配置文件:hive-site.xml
3、hive.auto.convert.join.noconditionaltask.size
默认值:10000000 (10M)
说明:这个参数使用的前提是hive.auto.convert.join.noconditionaltask值为true,多个mapjoin转换为1个时,所有小表的文件大小总和小于这个值,这个值只是限制输入的表文件的大小,并不代表实际mapjoin时hashtable的大小。 建议值:1/3* hive.tez.container.size
配置文件:hive-site.xml
4、tez.runtime.unordered.output.buffer.size-mb #如果不直接写入磁盘,使用的缓冲区大小
默认值:100M
建议:10%* hive.tez.container.size
配置文件:tez-site.xml
5、tez.am.container.reuse.enabled #容器重用
默认值:true
配置文件:tez-ste.xml
参考网址:https://www.cnblogs.com/yjt1993/p/11050791.html
e
配置文件:hive-site.xml
4、tez.runtime.unordered.output.buffer.size-mb #如果不直接写入磁盘,使用的缓冲区大小
默认值:100M
建议:10%* hive.tez.container.size
配置文件:tez-site.xml
5、tez.am.container.reuse.enabled #容器重用
默认值:true
配置文件:tez-ste.xml
参考网址:https://www.cnblogs.com/yjt1993/p/11050791.html
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/202914.html原文链接:https://javaforall.net
