减速器停留在70%

xj3cbfub  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(390)

我正在用hadoop编写一个非常初始的编程任务,并使用经典的wordcount问题。
已经在hdfs上放置了一个示例文件,并尝试在其上运行wordcount。Map器通过得很好,然而,减速器卡在70%,从不前进。
我也用本地文件系统上的文件尝试了这个方法,得到了相同的结果。
我会做错什么?以下是map和reduce函数-

  1. public void map(LongWritable key, Text value,
  2. OutputCollector<Text, IntWritable> output, Reporter reporter)
  3. throws IOException {
  4. // TODO Auto-generated method stub
  5. String line = value.toString();
  6. String[] lineparts = line.split(",");
  7. for(int i=0; i<lineparts.length; ++i)
  8. {
  9. output.collect(new Text(lineparts[i]), new IntWritable(1));
  10. }
  11. public void reduce(Text key, Iterator<IntWritable> values,
  12. OutputCollector<Text, IntWritable> output, Reporter reporter)
  13. throws IOException {
  14. // TODO Auto-generated method stub
  15. int count = 0;
  16. while(values.hasNext())
  17. {
  18. count=count+1;
  19. }
  20. output.collect(key , new IntWritable(count));
  21. }
0lvr5msh

0lvr5msh1#

你从不打电话 next() 在迭代器上,基本上创建了一个无限循环。
作为补充说明,实现这个单词计数示例的首选方法是不将计数递增 1 ,但改用值:

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

这样,你就可以重复使用你的电脑了 Reducer 作为一个 Combiner 因此,它将计算每个Map器的部分计数,并向reducer发出(“wordx”,7),而不是从给定Map器发出7次(“wordx”,1)。您可以在这里阅读更多关于合并器的信息。

相关问题