【发布时间】: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));
}
【问题讨论】: