簡體   English   中英

如何在Hadoop中以編程方式獲取每個減少任務的執行時間?

[英]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。 但是它只顯示一個時間戳。.我在這里做錯什么了嗎...

要查找減速器的總時間,您可以:

  1. 向該類添加一個long變量,該變量將保留開始時間。
  2. 在reducer的setup()方法中setup()開始時間。
  3. 在減速器的cleanup()方法中獲取結束時間,然后從存儲的開始時間中減去以獲取總時間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM