描述
执行 MapReduce 程序时,如下图:
一般会显示红框处,表示 未启动 uber 模式
uber模式
uber模式是 2.x
开始引入的;以 Uber
模式运行 MR 作业,所有的 Map Tasks
和 Reduce Tasks
将会在 ApplicationMaster
所在的容器(container
)中运行
即:整个 MR 作业运行的过程 只会 启动 AM container
。所有子task 与 ApplicationMaster 在同一个JVM中执行,达到JVM重用的目的。
因为不需要启动 mapper containers
和 reducer containers
,所以 AM 不需要 和远程 containers 通信,整个过程简单,执行速度快。
应用场景
如果 MR 作业 输入的数据量 非常小,启动 Map container
或 Reduce container
的时间都 比处理数据要长,那么这个作业就可以考虑启用 Uber
模式运行
一般情况下,对小作业启用 Uber 模式运行会得到 2-3
倍 的性能提升。
启用 Uber 模式的条件
启用 uber 模式的要求非常严格,代码如下:
isUber = uberEnabled && smallNumMapTasks && smallNumReduceTasks && smallInput && smallMemory && smallCpu && notChainJob && isValidUberMaxReduces;
同时满足上面 8个条件 才能启动 Uber 模式,解释:
uberEnabled:
yarn-site.xml
中mapreduce.job.ubertask.enable
参数的值,默认为false
,即:不启用 Uber 模式smallNumMapTasks:启用 Uber 模式的作业 Map 的个数必须小于等于
mapreduce.job.ubertask.maxmaps
参数的值,该值默认为 9;即:启用 Uber 模式,作业的 Map 个数必须小于 10;smallNumReduceTasks:同理,Uber 模式的作业 Reduce 的个数必须小于等于
mapreduce.job.ubertask.maxreduces
,该值默认为 1;即:启用 Uber 模式,作业的 Reduce 个数必须小于等于 1;smallInput:输入数据的大小必须 小于等于
mapreduce.job.ubertask.maxbytes
参数的值,默认情况是 HDFS 一个文件块大小;smallMemory:因为作业是在 AM 所在的 container 中运行,所以要求我们设置的 Map 内存(
mapreduce.map.memory.mb
)和 Reduce 内存(mapreduce.reduce.memory.mb
)必须 小于等于 AM 所在容器内存大小设置(yarn.app.mapreduce.am.resource.mb
);smallCpu:同理,Map 配置的 vcores(
mapreduce.map.cpu.vcores
)个数和 Reduce 配置的 vcores(mapreduce.reduce.cpu.vcores
)个数也必须小于等于 AM 所在容器 vcores 个数的设置(yarn.app.mapreduce.am.resource.cpu-vcores
);notChainJob:此外,处理数据的 Map class(
mapreduce.job.map.class
)和 Reduce class(mapreduce.job.reduce.class
)必须不是 ChainMapper 或 ChainReducer 才行;isValidUberMaxReduces:目前仅当 Reduce 的个数小于等于 1 的作业才能启用 Uber 模式。
测试:启用 uber 模式
修改 yarn-site.xml
修改 hadoop1
的 yarn-site.xml
文件,增加下面内容:
<property>
<name>mapreduce.job.ubertask.enable</name>
<value>true</value>
</property>
同步文件
同步到 hadoop2:
rsync -av /program/hadoop-3.0.3/etc/hadoop/* root@hadoop2:/program/hadoop-3.0.3/etc/hadoop/
同步到 hadoop3:
rsync -av /program/hadoop-3.0.3/etc/hadoop/* root@hadoop3:/program/hadoop-3.0.3/etc/hadoop/
重启 yarn
登录 hadoop2,执行下面命令:
stop-yarn.sh
start-yarn.sh
准备测试数据
创建文本文件 data.txt
,内容如下:
李雷
韩梅梅
lucy
lili
张三
李四
王五
李雷
韩梅梅
lucy
李雷
韩梅梅
李雷
上传到 HDFS 的 /test/data.txt
位置
测试 wordcount
下面命令解释,详见 链接
hadoop jar ${HADOOP_HOME}/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.0.3.jar wordcount /test/data.txt /result12300904
注意: 要满足上面8个条件,如:读取的文件 不能大于 HDFS 文件块大小
执行结果如下:
红框处显示:启用了 uber 模式
而且执行速度 明显快很多
感谢:
https://www.dazhuanlan.com/leotsui1988/topics/1645258
https://www.cnblogs.com/yanghaolie/p/7920674.html