hadoop之 mapreduce Combiner
2016-05-10 18:03
423 查看
许多mapreduce作业会受限与集群的带宽,因此尽量降低map和reduce任务之间的数据传输是有必要的。Hadoop允许用户针对map任务的输出指定一个combiner函数处理map任务的输出,并作为reduce函数的输入。因为combine是优化方案,所以Hadoop无法确定针对map输出记录需要调用多少次combine函数。in the other word,不管调用多少次combine函数,reducer的输出结果都是一样的。
The contract for the combiner function constrains the type of function that may be used。
combiner函数协议会制约可用的函数类型。举个例子:
假设第一个map输出如下:
第二个map输出如下:
reduce函数被调用时,其输入是
结果:
如果调用combine函数,像reduce函数一样去寻找 每个map的输出的最大温度。那么输出结果应该是:
reduce 输出结果和以前一样。可用通过下面的表达式来说明气温数值的函数调用:
并不是所有函数都有这个属性。例如,我们计算平均气温,就不能使用平均函数作为combiner。
但是:
combiner函数不能取代reducer。但它能有效减少mapper和reducer之间的数据传输量。
指定一个 combiner
The contract for the combiner function constrains the type of function that may be used。
combiner函数协议会制约可用的函数类型。举个例子:
假设第一个map输出如下:
(1950, 0) (1950, 20) (1950, 10)
第二个map输出如下:
(1950, 25) (1950, 15)
reduce函数被调用时,其输入是
(1950, [0, 20, 10, 25, 15])
结果:
(1950, 25)
如果调用combine函数,像reduce函数一样去寻找 每个map的输出的最大温度。那么输出结果应该是:
(1950, [20, 25])
reduce 输出结果和以前一样。可用通过下面的表达式来说明气温数值的函数调用:
max(0, 20, 10, 25, 15) = max(max(0, 20, 10), max(25, 15)) = max(20, 25) = 25
并不是所有函数都有这个属性。例如,我们计算平均气温,就不能使用平均函数作为combiner。
mean(0, 20, 10, 25, 15) = 14
但是:
mean(mean(0, 20, 10), mean(25, 15)) = mean(10, 20) = 15
combiner函数不能取代reducer。但它能有效减少mapper和reducer之间的数据传输量。
指定一个 combiner
Job job = Job.getInstance(); job.setJarByClass(MaxTemperatureJob.class); job.setJobName("max temperature"); //方法为什么不保持一致,不是一个人写的? FileInputFormat.addInputPath(job, new Path(INPUT_PATH)); FileOutputFormat.setOutputPath(job, new Path(OUT_PATH)); job.setMapperClass(MaxTemperatureMapper.class); job.setReducerClass(MaxTemperatureReducer.class); //设置combiner job.setCombinerClass(MaxTemperatureReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); // job.setInputFormatClass(); System.out.println(job.waitForCompletion(true) ? 0 : 1);
相关文章推荐
- hadoop之 mapreduce data flow
- hadoop之 mapreduce example(2)
- hadoop之 mapreduce example(1)
- Sqoop使用笔记
- docker学习笔记(六)使用Dockerfile构建镜像
- docker学习笔记(五): Dockerfile指令
- docker学习笔记(三): 简单的容器操作
- shell脚本加密工具
- 生成树状结构的脚本bat\python\shell
- openwrt中Makefile函数subset分析
- OC self = [super init] , 点语法 , @property
- SQLite3嵌入式数据库arm+linux移植
- 在Linux系统下编译并执行C++程序
- VS中一些warning的消除
- linux 性能优化
- (OK) IMUNES—Docker—Fedora23
- 脚本控制nginx的启动,关闭,重载等
- shell新增用户
- getopt()函数获取两个以上参数的方法
- nginx的启动 重启 关闭