MapReduce: combiner
来源:互联网 发布:php网上商城系统源码 编辑:程序博客网 时间:2024/06/06 04:23
1、什么是combiner?
combiner就是规约操作,通过对map输出的数量进行规约,可以减少reduce的数量,提高执行效率combiner的输入输出类型必须和mapper的输出以及reducer的输入类型一致
2、什么情况要使用 combiner,什么情况不使用?
求平均数的时候就不需要用combiner,因为不会减少reduce执行数量。在其他的时候,可以依据情况,使用combiner,来减少map的输出数量,减少拷贝到reduce的文件,从而减轻reduce的压力,节省网络开销,提升执行效率
3、combine出现在哪个过程
map阶段的最后一个过程。
4、combine代码实现
/*** * * <p>Description: 减少Reduce的压力,设置在job.setCombinerClass(WordCountReducer.class);中</p> * @author 余辉 * @date 2016年3月14日下午4:31:10 * @version 1.0 */public class WordCountCombiner extends Reducer<Text, IntWritable, Text, IntWritable>{ @Override protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { //定义一个计数器 int count = 0; //遍历这一组kv的所有v,累加到count中 for(IntWritable value:values){ count += value.get(); } context.write(key, new IntWritable(count)); }}
public class WordCountRunner { static class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable>{ protected void map(LongWritable key, Text value, Context context ) throws IOException, InterruptedException{ String line = value.toString(); String[] words = StringUtils.split(line, " "); for(String word : words){ context.write(new Text(word), new IntWritable(1)); } } } static class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> { protected void reduce(Text key, Iterable<IntWritable> values,Context context) throws IOException, InterruptedException{ int counter = 0; for(IntWritable value:values){ //累加每一个value counter += value.get(); } context.write(key, new IntWritable(counter)); } } public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { //封装任务信息的对象为Job对象,所以要先构造一个Job对象 Configuration conf = new Configuration(); Job job = Job.getInstance(conf); //设置本次job作业所在的jar包 job.setJarByClass(WordCountRunner.class); //本次job作业使用的mapper类是哪个? job.setMapperClass(WordCountMapper.class); //本次job作业使用的reducer类是哪个? job.setReducerClass(WordCountReducer.class); //指定自定义的combiner类 job.setCombinerClass(WordCountReducer.class); //本次job作业mapper类的输出数据key类型 job.setMapOutputKeyClass(Text.class); //本次job作业mapper类的输出数据value类型 job.setMapOutputValueClass(IntWritable.class); //本次job作业reducer类的输出数据key类型 job.setOutputKeyClass(Text.class); //本次job作业reducer类的输出数据value类型 job.setOutputValueClass(IntWritable.class); //本次job作业要处理的原始数据所在的路径 FileInputFormat.setInputPaths(job, new Path("/home/hadoop/Desktop/input")); //本次job作业产生的结果输出路径 FileOutputFormat.setOutputPath(job, new Path("/home/hadoop/Desktop/output")); //提交本次作业 job.waitForCompletion(true); }}
0 0
- MapReduce: combiner
- MapReduce--Combiner
- MapReduce之Combiner组件
- mapreduce之combiner
- hadoop之 mapreduce Combiner
- MapReduce中的Combiner类
- MAPREDUCE中的Combiner
- MapReduce编程之Combiner
- MapReduce(partation,sort,combiner)
- mapreduce的规约(Combiner)
- MapReduce程序开发中的Combiner
- mapreduce过程---combiner原理入门
- MapReduce中Combiner方法使用
- mapreduce中的partitioner,combiner,shuffle
- MapReduce之combiner的理解
- Mapreduce中Combiner的使用及误区
- Mapreduce中Combiner的使用及误区
- 关于mapreduce 的 shuffle ,partition,combiner
- C语言实现顺序表的所有操作代码
- 剑指offer-两个链表的第一个公共节点
- 深入理解requestAnimationFrame
- 【数论】[codevs 2952 细胞分裂]快速幂
- 基于数字图像处理的人民币碎片拼接
- MapReduce: combiner
- Practical Rendering and Computation with Direct3D 11学习笔记(1.4)
- Java线程详解
- 对不可用for update 的数据库管理工具如何复制记录
- String, StringBuilder与StringBuffer的区别
- Swift中的可选类型 (Optionals)与Objective-C中的nullability注解
- 12C-OCP升级1z-060-007
- 进程通信[概念比较]
- select下拉框之去掉重复