MapReduce程序开发中的Combiner
来源:互联网 发布:it培训公司排名 编辑:程序博客网 时间:2024/05/17 09:36
2016年4月4日10:46:2
MapReduce程序开发中的Combiner
作者:数据分析玩家
在MapReduce程序的运行过程中,经过shuffle阶段:分区、排序、分组之后,可以使用Combiner类进行进一步的处理,但是Combiner这个类究竟是做什么的,其使用的限制条件究竟是什么,本文将对Combiner类进行全面的阐述。
假设在WordCount程序中,我们读取的文件内容为:
hello you
hello me
如果在MapReduce程序中,我们不加入 job.setCombinerClass(MyCombiner.class);即不使用Combiner这个类,程序运行完之后,显示的计数器为:
Map-Reduce Framework
Map input records=2
Map output records=4
Reduce input records=4
Reduce input groups=3
Map output records=4
这是我们在不加入Combiner这个类时显示的计数器,可以看出Mapper任务传送给Reducer任务的组数是3,记录数是4
当我们在MapReduce加入job.setCombinerClass(MyCombiner.class)这一行代码时,程序运行完之后,显示的计数器情况为:
Map-Reduce Framework
Map input records=2
Map output records=4
Reduce input records=3
Reduce input groups=3
Map output records=4
当我们在加入Combiner这个类之后,可以看出Mapper任务传送给Reducer任务的组数是3,记录数是3,相比与之前的情况,我们发现记录数少了1个,这又是为什么呢?这个问题正好可以说明我们Combiner类的作用:Combiner这个类发生在每一个Mapper任务的内部,在每一个Mapper任务的内部对每一个键值对<k2,v2s>先进行一次合并,将大的数据集合变成小的数据集合,也就是说本来一个Mapper任务处理之后传送给Reducer任务的应该是键值对<hello,{1,1}>,但是由于Combiner这个类先进行了一次的合并,传送给Reducer任务的数据变成了<hello,2>,因此记录数减少了1个。
通过实例运行之后,我们从以下几个方面对归约即Combiner类的作用进行阐述:
1>为什么要使用Combiner,Combiner所起的作用是什么?
Combiner最基本的作用是实现本地key的归并,combiner具有类似本地Reducer的功能.
Combiner发生在每一个Mapper任务的末尾端,对数据进行规约处理,对输出的数据<k2,v2s>先做一次合并,进而传送到Reducer任务的数据量变小了,传输时间变短,作业的整体时间变短.
图示如下:
2>combiner归约使用的限制条件是什么?
只有当<k2,v2>的数据类型与<k3,v3>的数据类型完全相同的时候,才能够在MapReduce程序中加入归约这个步骤,例如:在WordCount程序中,<k2,v2>的数据类型是<Text,LongWritable>而<k3,v3>的数据类型也是
<Text,LongWritable>,所以本程序可以使用Combiner这个步骤
3>如何使用combiner这个类?
在程序中加入job.setCombinerClass(MyReducer.class)这行代码即可。
2016年4月4日11:32:20
- MapReduce程序开发中的Combiner
- MapReduce中的Combiner类
- MAPREDUCE中的Combiner
- mapreduce中的partitioner,combiner,shuffle
- MapReduce: combiner
- MapReduce--Combiner
- [Hadoop]MapReduce中的Partitioner与Combiner
- MapReduce程序开发中的Partitioner
- MapReduce程序开发中的context
- MapReduce中的combiner、partition和shuffle各自的作用是什么?
- MapReduce之Combiner组件
- mapreduce之combiner
- hadoop之 mapreduce Combiner
- MapReduce编程之Combiner
- MapReduce(partation,sort,combiner)
- MapReduce程序开发中的FileInputFormat与TextInputFormat
- mapreduce的规约(Combiner)
- mapreduce过程---combiner原理入门
- OOD 面向对象设计规范(总结)
- 欢迎使用CSDN-markdown编辑器
- Nginx日志增长过快详细分析
- 遇到问题----Android----ActivityManager: Error: Activity class {xx/xx.MainActivity} does not exist
- 清空数据库并将id从1开始排序
- MapReduce程序开发中的Combiner
- dpi 、 dip 、分辨率、屏幕尺寸、px、density 关系以及换算
- 一些说说总结(自勉)--对于攀登者来说,失掉往昔的足迹并不可惜,迷失了继续前时的方向却很危险
- JavaWeb - 浏览器与服务器交互的过程
- 命令窗口查看执行计划不全
- nginx配置与使用
- Unity5的关卡切换
- codevs 1017 乘积最大
- 一些可能还是碎片化的知识和认识