zoukankan      html  css  js  c++  java
  • [MapReduce_5] MapReduce 中的 Combiner 组件应用


    0. 说明

      Combiner 介绍 &&  在 MapReduce 中的应用


    1. 介绍

      Combiner:

      Map 端的 Reduce,有自己的使用场景

      在相同 Key 过多的情况下,在 Map 端进行的预聚合,大大缓解了网络间的 K-V 全分发

      Combiner 适用场景:

    1. 最大值
    2. 求和
    3. 最小值

      Combiner 不适用平均值的计算


     2. 结合 Combiner 实现 Word Count

      在 [MapReduce_1] 运行 Word Count 示例程序 代码基础上在 WCApp.java 中添加了以下内容

      


     3. 结合 Combiner 实现最高气温统计

       在 [MapReduce_add_2] MapReduce 实现年度最高气温统计 代码基础上进行改进

      【3.1 编写 MaxTempCombiner.java】

    package hadoop.mr.combiner;
    
    import org.apache.hadoop.io.IntWritable;
    import org.apache.hadoop.io.Text;
    import org.apache.hadoop.mapreduce.Reducer;
    
    import java.io.IOException;
    
    /**
     * Combiner 类
     */
    public class MaxTempCombiner extends Reducer<Text, IntWritable, Text, IntWritable> {
        @Override
        protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
            Integer max = Integer.MIN_VALUE;
    
            // 得到最大值
            for (IntWritable value : values) {
                max = Math.max(max, value.get());
            }
    
            // 输出年份与最大温度
            context.write(key, new IntWritable(max));
        }
    }

      【3.2 修改 MaxTempApp.java】

       


  • 相关阅读:
    k8s蓝绿
    nginx总结
    promethues监控 之 TCP连接数
    制作私有ssl证书
    redis命令
    zabbix主机自动发现
    Kubernetes各组件服务重启
    linxu下常用命令
    encodeURIComponent
    查询条件
  • 原文地址:https://www.cnblogs.com/share23/p/9779568.html
Copyright © 2011-2022 走看看