后端 MapReduce 作业Uber模式介绍

leotsui1988 · March 28, 2020 · 44 hits

提交 MapReduce 作业时 肯定看过如下的输出:

17/04/17 14:00:38 INFO mapreduce.Job: Running job: job_1472052053889_0001
17/04/17 14:00:48 INFO mapreduce.Job: Job job_1472052053889_0001 running in uber mode : false
17/04/17 14:00:48 INFO mapreduce.Job: map 0% reduce 0%
17/04/17 14:00:58 INFO mapreduce.Job: map 100% reduce 0%
17/04/17 14:01:04 INFO mapreduce.Job: map 100% reduce 100%

注意上面日志的第二行,显示 job_1472052053889_0001 不是以uber模式运行的。

什么是 uber 模式

该模式是 2.x 开始引入的;以 Uber 模式运行 MR 作业,所有的 Map Tasks 和 Reduce Tasks 将会在 ApplicationMaster 所在的容器(container)中运行,即

整个 MR 作业运行的过程只会启动 AM container,

因为不需要启动 mapper 和 reducer containers,所以 AM 不需要和远程 containers 通信,整个过程简单了。

uber 模式一般用处

如果我们的 MR 作业输入的数据量非常小,启动 Map container 或 Reduce container 的时间都比处理数据要长,那么这个作业就可以考虑启用 Uber 模式运行,一般情况下,对小作业启用 Uber 模式运行会得到 2x-3x 的性能提升。

如何启用 Uber 模式

启用 uber 模式的要求非常严格,代码如下:

isUber = uberEnabled && smallNumMapTasks && smallNumReduceTasks && smallInput && smallMemory && smallCpu && notChainJob && isValidUberMaxReduces;

  • uberEnabled:其实就是 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:不是任何作业都适合启用 Uber 模式的,输入数据的大小必须小于等于 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 模式。下面是一个启用 Uber 模式运行的作业运行成功的日志:

File System Counters FILE: Number of bytes read=215 FILE: Number of bytes written=505 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=1200 HDFS: Number of bytes written=274907 HDFS: Number of read operations=57 HDFS: Number of large read operations=0 HDFS: Number of write operations=11 Job Counters Launched map tasks=2 Launched reduce tasks=1 Other local map tasks=2 Total time spent by all maps in occupied slots (ms)=3664 Total time spent by all reduces in occupied slots (ms)=2492 TOTAL_LAUNCHED_UBERTASKS=3 NUM_UBER_SUBMAPS=2 NUM_UBER_SUBREDUCES=1 Map-Reduce Framework Map input records=2 Map output records=8 Map output bytes=82 Map output materialized bytes=85 Input split bytes=202 Combine input records=8 Combine output records=6 Reduce input groups=5 Reduce shuffle bytes=0 Reduce input records=6 Reduce output records=5 Spilled Records=12 Shuffled Maps =0 Failed Shuffles=0 Merged Map outputs=0 GC time elapsed (ms)=65 CPU time spent (ms)=1610 Physical memory (bytes) snapshot=1229729792 Virtual memory (bytes) snapshot=5839392768 Total committed heap usage (bytes)=3087532032 File Input Format Counters Bytes Read=50 File Output Format Counters Bytes Written=41

细心的同学应该会发现里面多了 TOTAL_LAUNCHED_UBERTASKS、NUM_UBER_SUBMAPS 以及 NUM_UBER_SUBREDUCES 信息,以前需要启用 Map Task 或 Reduce Task 运行的工作直接在 AM 中运行,所有出现了 NUM_UBER_SUBMAPS 和原来 Map Task 个数一样;同理,NUM_UBER_SUBREDUCES 和 Reduce Task 个数一样。

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.