【问题标题】:reducer stuck at 70%减速机卡在 70%
【发布时间】:2016-08-22 02:53:50
【问题描述】:

我正在使用 hadoop 编写一个非常初始的编程任务,并解决经典的字数问题。

已经在 hdfs 上放了一个示例文件,并尝试在其上运行 wordcount。 mapper 运行良好,但是 reducer 卡在 70%,永远不会前进。

我也对本地文件系统上的文件进行了尝试,并且得到了相同的行为。

我可能做错了什么? 这里是 map 和 reduce 函数 -

public void map(LongWritable key, Text value,
        OutputCollector<Text, IntWritable> output, Reporter reporter)
        throws IOException {
    // TODO Auto-generated method stub
    String line = value.toString();

    String[] lineparts = line.split(",");

    for(int i=0; i<lineparts.length; ++i)
    {
        output.collect(new Text(lineparts[i]), new IntWritable(1));
    }


public void reduce(Text key, Iterator<IntWritable> values,
              OutputCollector<Text, IntWritable> output, Reporter reporter)
            throws IOException {
        // TODO Auto-generated method stub
        int count = 0;
        while(values.hasNext())
        {
            count=count+1;
        }
        output.collect(key , new IntWritable(count));
    }

【问题讨论】:

    标签: hadoop mapreduce


    【解决方案1】:

    你永远不会在你的迭代器上调用next(),所以你基本上是在创建一个无限循环。


    附带说明,实现此字数统计示例的首选方法不是将计数增加1,而是使用该值:

    IntWritable value = values.next();
    count += value.get();
    

    这样,您可以将您的 Reducer 重用为 Combiner,以便它计算每个映射器的部分计数并将 ("wordX", 7) 发送到减速器,而不是 7 次出现 ("wordX", 1)来自给定的映射器。您可以阅读有关组合器的更多信息here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 2018-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多