2016-08-21 42 views
0

我正在與hadoop一起編寫一個非常初始的編程任務,並且還會使用經典的wordcount問題。減速器停留在70%

已經在hdfs上放了一個示例文件,並試圖在其上運行wordcount。映射器經過得很好,但是,減速器停留在70%,永遠不會前進。

我也嘗試過使用本地文件系統上的文件,並獲得相同的行爲。

我能做什麼錯? 這裏有地圖和減少功能 -

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)); 
    } 

回答

3

你永遠不叫你的迭代器next(),所以你基本上是創建一個無限循環。


作爲一個側面說明,要實現這個字數例子的首選方法是不是1遞增計數,但使用的值改爲:

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

這樣,您就可以重用Reducer作爲Combiner,以便它將計算每個映射器的部分計數,並從給定的映射器向reducer發出(「wordX」,7)而不是7次出現的(「wordX」,1)。你可以閱讀更多關於梳妝檯here

+0

完美,感謝您快速查找錯誤。 – Gyan