mapreduce中组合器和映射器组合器之间的区别?

时间:2015-01-28 17:42:47

标签: hadoop mapreduce combiners

我是hadoop和mapreduce的新手。有人可以澄清组合器和映射器组合器之间的区别,还是它们是相同的东西?

1 个答案:

答案 0 :(得分:5)

您可能已经意识到,组合器是一个在每个Mapper计算机上本地运行的进程,用于在将数据通过网络混洗到各个群集Reducers之前预先聚合数据。

映射器内组合器进一步优化了这种优化:聚合甚至不写入本地磁盘:它们在Mapper本身中出现 in-memory 。 / p>

映射器内组合器通过利用

的setup()和cleanup()方法来实现这一点。
org.apache.hadoop.mapreduce.Mapper

沿着以下行创建内存映射:

Map<LongWritable, Text> inmemMap = null
   protected void setup(Mapper.Context context) throws IOException, InterruptedException {
   inmemMap  = new Map<LongWritable, Text>();
 }

然后在每次map()调用期间,你要在内存映射中添加值(而不是在每个值上调用context.write()。最后Map / Reduce框架会自动调用:

protected void cleanup(Mapper.Context context) throws IOException, InterruptedException {
  for (LongWritable key : inmemMap.keySet()) {
      Text myAggregatedText = doAggregation(inmemMap.get(key))// do some aggregation on 
                   the inmemMap.     
      context.write(key, myAggregatedText);
  }
}

请注意,不是每次都调用context.write(),而是将条目添加到内存映射中。然后在cleanup()方法中调用context.write(),但使用内存映射中的压缩/预聚合结果。因此,本地地图输出假脱机文件(将由reducer读取)将小得多。

在这两种情况下 - 无论是内存还是外部组合器 - 由于较小的映射假脱机文件,您可以获得减少网络流量的好处。这也减少了减速机的处理。