1、什么是 Combiner
Combiner 是 MapReduce 程序中 Mapper 和 Reducer 之外的一种组件,它的作用是在 maptask 之后给 maptask 的结果进行局部汇总,以减轻 reducetask 的计算负载,减少网络传输
2、如何使用 Combiner
Combiner 和 Reducer 一样,编写一个类,然后继承 Reducer,reduce 方法中写具体的 Combiner 逻辑,然后在 job 中设置 Combiner 组件:job.setCombinerClass(FlowSumCombine.class)
3、使用 Combiner 注意事项
- Combiner 和 Reducer 的区别在于运行的位置: Combiner 是在每一个 MapTask 所在的节点运行
- Stay hungry Stay foolish -- http://blog.csdn.net/zhongqi2513
- Reducer 是接收全局所有 Mapper 的输出结果
- Combiner 的输出 kv 类型应该跟 Reducer 的输入 kv 类型对应起来 Combiner 的输入 kv 类型应该跟 Mapper 的输出 kv 类型对应起来
- Combiner 的使用要非常谨慎,因为 Combiner 在 MapReduce 过程中可能调用也可能不调 用,可能调一次也可能调多次,所以: Combiner 使用的原则是:有或没有都不能影响业务逻辑,都不能影响最终结果