繁体   English   中英

MapReduce中的合并器和映射器合并器之间的区别?

[英]Difference between combiner and in-mapper combiner in mapreduce?

我是hadoop和mapreduce的新手。 有人可以澄清组合器和映射器中的组合器之间的区别吗,或者它们是同一回事?

您可能已经知道,合并器是在每台Mapper机器上本地运行的进程,用于在将数据通过网络重新整理到各个Cluster Reducer之前对其进行预聚合。

映射器内组合器进一步优化了该聚合:聚合甚至没有写入本地磁盘:聚合发生 Mapper本身的内存中。

映射器内组合器通过利用以下内容的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读取)将小得多。

在这两种情况下(在内存和外部组合器中),由于较小的映射假脱机文件,您将获得减少到简化器的网络流量的好处。 这也减少了减速器的处理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM