[英]How do I get each reduce task's execution time programmatically in Hadoop?
我正在hadoop中運行一個簡單的map reduce作業,在Java中,我可以使用System.currentTimeInMillis()
函數來計算開始時間和結束時間,在mapreduce中,我該如何為地圖(endTime-startTime)完成此功能,reduce( endTime-startTime)。 我嘗試了以下代碼..並set job.setNumReduceTasks(4)
編輯:
public void reduce(Text _key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
// process values
long start=System.currentTimeMillis();
int sum=0;
for (IntWritable val : values) {
sum+=val.get();
}
result.set(sum);
context.write(_key, result);
long end=System.currentTimeMillis();
System.out.println(" time Taken "+(end-start));
}
但結果是:
time Taken 1
time Taken 0
time Taken 0
time Taken 0
time Taken 0
time Taken 0
time Taken 0
time Taken 0
time Taken 0
time Taken 0
----------
----------
但我將reduce任務的數量設置為4 ..並且這里顯示了執行每個鍵值對所花費的時間。
添加setup()方法和cleanup()方法之后。
public void run(Context context) throws IOException, InterruptedException {
start=System.currentTimeMillis();
setup(context);
try {
while (context.nextKey()) {
reduce(context.getCurrentKey(), context.getValues(), context);
}
} finally {
cleanup(context);
end=System.currentTimeMillis();
System.out.println(" End- Start : "+(end-start));
}
}
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);
}
我已經使用job.setNumReduceTasks(4)
將reducer的數量設置為4。 但是它只顯示一個時間戳。.我在這里做錯什么了嗎...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.