2011-07-11 45 views
8

Tôi hiện đang cố gắng tìm ra khi bạn chạy một công việc MapReduce điều gì xảy ra bằng cách tạo một số system.out.println() tại một số nơi trên mã nhưng biết về các lệnh in đó được in trên thiết bị đầu cuối của tôi khi công việc chạy. Ai đó có thể giúp tôi ra con số chính xác những gì tôi đang làm sai ở đây.MapReduce Lệnh không hiển thị các câu lệnh in trên thiết bị đầu cuối

import java.io.IOException; 
import java.util.StringTokenizer; 
import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.io.IntWritable; 
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.mapreduce.InputSplit; 
import org.apache.hadoop.mapreduce.Job; 
import org.apache.hadoop.mapreduce.Mapper; 
import org.apache.hadoop.mapreduce.OutputCommitter; 
import org.apache.hadoop.mapreduce.RecordReader; 
import org.apache.hadoop.mapreduce.RecordWriter; 
import org.apache.hadoop.mapreduce.Reducer; 
import org.apache.hadoop.mapreduce.StatusReporter; 
import org.apache.hadoop.mapreduce.TaskAttemptID; 
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 

public class WordCountJob { 
    public static int iterations; 
    public static class TokenizerMapper 
    extends Mapper<Object, Text, Text, IntWritable>{ 

private final static IntWritable one = new IntWritable(1); 
private Text word = new Text(); 
@Override 
public void map(Object key, Text value, Context context 
       ) throws IOException, InterruptedException { 
    System.out.println("blalblbfbbfbbbgghghghghghgh"); 
    StringTokenizer itr = new StringTokenizer(value.toString()); 
    while (itr.hasMoreTokens()) { 
    word.set(itr.nextToken()); 
    String myWord = itr.nextToken(); 
    int n = 0; 
    while(n< 5){ 
     myWord = myWord+ "Test my appending words"; 
     n++; 
    } 
    System.out.println("Print my word: "+myWord); 
    word.set(myWord); 
    context.write(word, one); 
    } 
} 
} 

public static class IntSumReducer 
    extends Reducer<Text,IntWritable,Text,IntWritable> { 
private IntWritable result = new IntWritable(); 

public void reduce(Text key, Iterable<IntWritable> values, 
        Context context 
        ) throws IOException, InterruptedException { 
    int sum = 0; 
    for (IntWritable val : values) { 
    sum += val.get(); 
    } 
    result.set(sum); 
    context.write(key, result); 
    } 
} 

public static void main(String[] args) throws Exception { 
Configuration conf = new Configuration(); 
TaskAttemptID taskid = new TaskAttemptID(); 
TokenizerMapper my = new TokenizerMapper(); 

if (args.length != 3) { 
    System.err.println("Usage: WordCountJob <in> <out> <iterations>"); 
    System.exit(2); 
} 
iterations = new Integer(args[2]); 
Path inPath = new Path(args[0]); 
Path outPath = null; 
for (int i = 0; i<iterations; ++i){ 
    System.out.println("Iteration number: "+i); 
    outPath = new Path(args[1]+i); 
    Job job = new Job(conf, "WordCountJob"); 
    job.setJarByClass(WordCountJob.class); 
    job.setMapperClass(TokenizerMapper.class); 
    job.setCombinerClass(IntSumReducer.class); 
    job.setReducerClass(IntSumReducer.class); 
    job.setOutputKeyClass(Text.class); 
    job.setOutputValueClass(IntWritable.class); 
    FileInputFormat.addInputPath(job, inPath); 
    FileOutputFormat.setOutputPath(job, outPath); 
    job.waitForCompletion(true); 
    inPath = outPath; 
    } 
} 
} 

Trả lời

20

Điều này phụ thuộc vào cách bạn đang trình công việc của bạn, tôi nghĩ rằng bạn đang gửi nó bằng cách sử bin/hadoop jar yourJar.jar phải không?

System.out.println() chỉ có sẵn trong phương pháp chính của bạn, đó là do trình ánh xạ/bộ giảm tốc được thực hiện bên trong hadoop trong một JVM khác. Và tôi sẽ khuyên bạn nên sử dụng riêng Apache-commons bạn log sử dụng:

Log log = LogFactory.getLog(YOUR_MAPPER_CLASS.class) 

Và do đó làm một số thông tin đăng nhập:

log.info("Your message"); 

Nếu bạn đang ở -mode "địa phương", sau đó bạn có thể nhìn thấy đăng nhập này trong trình bao của bạn, nếu không nhật ký này sẽ được lưu trữ ở đâu đó trên máy nơi tác vụ được thực hiện. Vui lòng sử dụng giao diện người dùng web của công việc để xem các tệp nhật ký này, nó khá thuận tiện. Theo mặc định, trình theo dõi công việc chạy trên cổng 50030.

+0

nhỏ sửa đổi/gợi ý SLF4J dường như phổ biến hơn ngày nay vì sự ràng buộc tĩnh – jayunit100

+2

@ jayunit100 vâng. Điều thú vị về việc đăng nhập commons là các lọ đã có sẵn vì Hadoop cũng sử dụng nó. Đối với SLF4J, điều này phải được thêm thông qua libjars. –

1

Hoặc, bạn có thể sử dụng lớp MultipleOutputs và chuyển hướng lại tất cả dữ liệu nhật ký của bạn vào một tệp đầu ra (nhật ký).

MultipleOutputs<Text, Text> mos = new MultipleOutputs<Text, Text>(context); 
Text tKey = new Text("key"); 
Text tVal = new Text("log message"); 
mos.write(tKey, tVal, <lOG_FILE>); 
Các vấn đề liên quan