combiners 进行map端的reduce
combiners
是在map端进行的一个reduce阶段
如
wordCount 程序
节点1map输出
hello 1
hadoop 1
hello 1
hello 1
节点2map输出
hello 1
hadoop 1
hadoop 1
通过combiners 就可以进行预先的聚合
变成 节点1 <hadoop,[1]>, <hello,[3]>
节点2 <hadoop, [2]>, <hello, [1]>到reduce
就不会节点每个单词就输出一遍 减少数据流量
这在性能上能够大大提高
因为等待网络传输数据 数据读取写入 是需要很大代销的 减少代销很重要
由于 在wordCount 中 做combiners 是跟reduce 一样的 可以直接使用reduce 类去进行 combiners
job.setCombinerClass(ReducerClass.class);
但是值得注意的是
如果用来计算平均值就需要注意
打个比方
(1+2+3+4+5+6+7+8+9)/9 = 5
如果第一个节点计算的是
(1+2+3+4+5)/5 = 3
节点2 计算余下部分
(6+7+8+9)/4 = 7
reduce 3+7 = 10
计算就会出错 要特别注意这点
本文转自 拖鞋崽 51CTO博客,原文链接:http://blog.51cto.com/1992mrwang/1206352