提交 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模式
运行的。
该模式是 2.x 开始引入的;以 Uber 模式运行 MR 作业,所有的 Map Tasks 和 Reduce Tasks 将会在 ApplicationMaster 所在的容器(container)中运行,即
整个 MR 作业运行的过程只会启动 AM container,
因为不需要启动 mapper 和 reducer containers,所以 AM 不需要和远程 containers 通信,整个过程简单了。
如果我们的 MR 作业输入的数据量非常小,启动 Map container 或 Reduce container 的时间都比处理数据要长,那么这个作业就可以考虑启用 Uber 模式运行,一般情况下,对小作业启用 Uber 模式运行会得到 2x-3x 的性能提升。
启用 uber 模式的要求非常严格,代码如下:
isUber = uberEnabled && smallNumMapTasks && smallNumReduceTasks && smallInput && smallMemory && smallCpu && notChainJob && isValidUberMaxReduces;
同时满足上面八个条件才能在作业运行的时候启动 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 个数一样。