hadoop - 组合器在哪里组合映射器输出 - 在 Map 阶段或 Map-reduce 作业中的 reduce 阶段?

标签 hadoop mapreduce hadoop2

我的印象是,组合器就像作用于本地 map 任务的 reducer,即它聚合单个 Map 任务的结果,以减少输出传输的网络带宽。

通过阅读 Hadoop - The definitive guide 3rd edition,我的理解似乎是正确的。

来自第 2 章(第 34 页)

组合器函数 许多 MapReduce 作业受到集群上可用带宽的限制,因此尽量减少 map 和 reduce 任务之间传输的数据是值得的。 Hadoop 允许用户指定要在 map 输出上运行的组合器函数——组合器函数的输出构成 reduce 函数的输入。由于 combiner 函数是一种优化,Hadoop 不保证为特定映射输出记录调用它的次数(如果有的话)。换句话说,零次、一次或多次调用组合器函数应该从缩减器产生相同的输出。

所以我在 wordcount 问题上尝试了以下方法:

job.setMapperClass(mapperClass);
job.setCombinerClass(reduceClass);
job.setNumReduceTasks(0);

这是计数器:

14/07/18 10:40:15 INFO mapred.JobClient: Counters: 10
14/07/18 10:40:15 INFO mapred.JobClient:   File System Counters
14/07/18 10:40:15 INFO mapred.JobClient:     FILE: Number of bytes read=293
14/07/18 10:40:15 INFO mapred.JobClient:     FILE: Number of bytes written=75964
14/07/18 10:40:15 INFO mapred.JobClient:     FILE: Number of read operations=0
14/07/18 10:40:15 INFO mapred.JobClient:     FILE: Number of large read operations=0
14/07/18 10:40:15 INFO mapred.JobClient:     FILE: Number of write operations=0
14/07/18 10:40:15 INFO mapred.JobClient:   Map-Reduce Framework
14/07/18 10:40:15 INFO mapred.JobClient:     Map input records=7
14/07/18 10:40:15 INFO mapred.JobClient:     Map output records=16
14/07/18 10:40:15 INFO mapred.JobClient:     Input split bytes=125
14/07/18 10:40:15 INFO mapred.JobClient:     Spilled Records=0
14/07/18 10:40:15 INFO mapred.JobClient:     Total committed heap usage (bytes)=85000192

这里是part-m-00000:

hello   1
world   1
Hadoop  1
programming 1
mapreduce   1
wordcount   1
lets    1
see 1
if  1
this    1
works   1
12345678    1
hello   1
world   1
mapreduce   1
wordcount   1

很明显没有应用组合器。我知道 Hadoop 根本不保证是否会调用组合器。但是当我打开 reduce 阶段时,会调用组合器。

为什么会出现这种行为?

现在,当我阅读关于 MapReduce 工作原理 的第 6 章(第 208 页)时。我在 Reduce side 中看到了这段描述。

如果 map 输出足够小,它们将被复制到 reduce 任务 JVM 的内存中(缓冲区的大小由 mapred.job.shuffle.input.buffer.percent 控制,它指定要使用的堆的比例以此目的);否则,它们被复制到磁盘。当内存缓冲区达到阈值大小时(由 mapred.job.shuffle.merge.percent 控制),或达到映射输出的阈值数量(mapred.inmem.merge.threshold),它被合并并溢出到磁盘。如果指定了组合器,它将在合并期间运行以减少写入磁盘的数据量。

我从这一段得出的推论是: 1) Combiner ALSO 在 reduce 阶段运行。

最佳答案

combiner 的主要功能是优化。在大多数情况下,它就像一个小型 reducer 。来自同一本书的第 206 页,章节 - mapreduce 的工作原理( map 方面):

Running the combiner function makes for a more compact map output, so there is less data to write to local disk and to transfer to the reducer.

引用你的问题,

If a combiner is specified it will be run during the merge to reduce the amount of data written to disk.

两个引号都表明 combiner 的运行主要是为了紧凑。减少输出传输的网络带宽是此优化的一个优势。

另外,来自同一本书,

Recall that combiners may be run repeatedly over the input without affecting the final result. If there are only one or two spills, then the potential reduction in map output size is not worth the overhead in invoking the combiner, so it is not run again for this map output.

这意味着 hadoop 不保证组合器运行了多少次(也可能为零)

combiner 永远不会为 map-only 作业运行。这是有道理的,因为组合器会更改 map 输出。此外,由于它不保证被调用的次数,因此也不能保证映射输出相同。

关于hadoop - 组合器在哪里组合映射器输出 - 在 Map 阶段或 Map-reduce 作业中的 reduce 阶段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24830928/

相关文章:

hadoop - Mapreduce多图和化简

java - 从Hive读取表格而没有 map 减少

java - 当我在 mapreduce 框架中设置 Split size 大于实际 Block size 时会发生什么?

hadoop - 将二进制数据从HDFS文件写入SequenceFile

在 Windows 10 上安装 Apache hadoop

java - hadoop中的 block 池

java - 无法使用 Hadoop 启动 Oryx

shell - 运行 Hbase shell 时出错

hadoop - 使用 Google Cloud Dataflow 合并 Google Cloud Storage 中的文件

java - 在 Hadoop 中并行化 Ruby reducer?