Bil*_*y02 5 hadoop mapreduce combiners
我是hadoop和mapreduce的新手.有人可以澄清组合器和映射器组合器之间的区别,还是它们是同一个东西?
您可能已经意识到组合器是一个在每台Mapper机器上本地运行的进程,用于在数据通过网络混洗到各种群集Reducers之前预先聚合数据.
映射器内组合器进一步优化了这种优化:聚合甚至不写入本地磁盘:它们出现在 Mapper本身的内存中.
映射器内组合器通过利用setup()和cleanup()方法来实现这一点
org.apache.hadoop.mapreduce.Mapper
Run Code Online (Sandbox Code Playgroud)
按以下行创建内存映射:
Map<LongWritable, Text> inmemMap = null
protected void setup(Mapper.Context context) throws IOException, InterruptedException {
inmemMap = new Map<LongWritable, Text>();
}
Run Code Online (Sandbox Code Playgroud)
然后在每次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);
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,不是每次都调用context.write(),而是将条目添加到内存映射中.然后在cleanup()方法中调用context.write(),但使用内存映射中的压缩/预聚合结果.因此,本地地图输出假脱机文件(将由reducer读取)将小得多.
在这两种情况下 - 无论是内存还是外部组合器 - 由于较小的映射假脱机文件,您可以获得减少网络流量的好处.这也减少了减速器的处理.
| 归档时间: |
|
| 查看次数: |
5330 次 |
| 最近记录: |