2014-05-08 3 views
1

하둡에서 새롭다. 매퍼마다 전송할 데이터 세트를 나누기 위해 각 실행마다 2, 4, 6 노드를 사용하고 싶다. 하지만 필자가 작성한 코드는 제대로 작동하지 않습니다. 실제로 그것은 2 개의 노드에서 작동하지만 노드의 수가 증가하면 출력 파일에서 손실되는 일부 출력 데이터가 증가합니다. 도와 주시겠습니까?하둡 Java로 다중 노드 프로그래밍

public static void main(String[] args) throws Exception { 


     System.out.println("MapReduce Started at:"+System.currentTimeMillis()); 
     Configuration conf = new Configuration(); 
     FileSystem fs = FileSystem.get(conf); 
     int numOfNodes = 2; 

     Job job = new Job(conf, "calculateSAAM"); 
     job.setJarByClass(calculateSAAM.class); 
     job.setOutputKeyClass(Text.class); 
     job.setOutputValueClass(DoubleWritable.class); 

     job.setMapperClass(Map.class); 
     job.setReducerClass(Reduce.class); 

     job.setInputFormatClass(TextInputFormat.class); 
     job.setOutputFormatClass(TextOutputFormat.class); 

     FileInputFormat.addInputPath(job, new Path("/home/helsene/wordcount/input")); 
     String outputFile = "/home/helsene/wordcount/output/"; 

     long dataLength = fs.getContentSummary(new Path(outputFile)).getLength(); 
     FileInputFormat.setMaxInputSplitSize(job, (dataLength/numOfNodes)); 

     job.setNumReduceTasks(numOfNodes/2); 
     Path outPath = new Path(outputFile); 

     fs.delete(outPath, true); 
     FileOutputFormat.setOutputPath(job, new Path(outputFile)); 

     job.waitForCompletion(true); 
     System.out.println("MapReduce ends at:"+System.currentTimeMillis()); 
     }   
    } 

답변

0

각 감속기가 (두 번째 감속기 등을위한 최초의 감속기, part-00001에 대한 part-00000) 기본 part-xxxxx에 의해 명명 하나 개의 출력 파일을 생성합니다 : 당신이 여기

감사하는 코드입니다.

노드가 3 개 이상인 경우 코드 작성기에 둘 이상의 축소 기가 있으므로 출력 데이터가 여러 파일 (두 개 이상의 파일)로 분할됩니다. 즉, 일부 단어 수는 첫 번째 파일 (part-00000)에 있고 일부 단어 수는 두 번째 파일 (part-00001)에 있습니다. 나중에

과 같은 getmerge 명령을 호출하여 이러한 부분을 병합 할 수 있습니다
hadoop dfs -getmerge /HADOOP/OUTPUT/PATH /local/path/ 

모든 부분 파일의 병합 된 결과로 지정한 로컬 경로에서 하나의 파일을 가져옵니다. 이 파일은 두 개의 노드가 있고 따라서 2/2 = 1 감속기 (하나의 출력 파일 생성)가있을 때 얻는 파일과 동일한 결과를 갖습니다.

그런데 감속기의 수를 numOfNodes/2으로 설정하는 것이 최선의 방법은 아닙니다. 자세한 내용은 this post을 참조하십시오.

+0

고맙습니다. 이것은 해결책이었습니다 – Suzi

+0

@Maryam 제가 도와 줬기 때문에 기쁩니다! 다른 사람들이 해결책을 알기 위해서는 내 대답을 인정 된 것으로 표시 할 수 있습니다. – vefthym