閱讀291 返回首頁    go 微軟 go windows


sleep示例__示例程序_MapReduce_大數據計算服務-阿裏雲

(1)準備好測試程序jar包,假設名字為mapreduce-examples.jar;

(2)準備好SleepJob的資源;

  add jar mapreduce-examples.jar -f;

測試步驟

在odpscmd中執行Sleep

  jar -resources mapreduce-examples.jar -classpath mapreduce-examples.jar 
        com.aliyun.odps.mapred.open.example.Sleep 10;
  jar -resources mapreduce-examples.jar -classpath mapreduce-examples.jar 
        com.aliyun.odps.mapred.open.example.Sleep 100;

預期結果

作業成功結束。 對比不同sleep時長的運行時間,可以看到效果。

代碼示例

package com.aliyun.odps.mapred.open.example;

import java.io.IOException;

import com.aliyun.odps.mapred.JobClient;
import com.aliyun.odps.mapred.MapperBase;
import com.aliyun.odps.mapred.conf.JobConf;

public class Sleep {

  private static final String SLEEP_SECS = "sleep.secs";

  public static class MapperClass extends MapperBase {

    @Override
    public void setup(TaskContext context) throws IOException {
      try {
        Thread.sleep(context.getJobConf().getInt(SLEEP_SECS, 1) * 1000);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
  }

  public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      System.err.println("Usage: Sleep <sleep_secs>");
      System.exit(-1);
    }

    JobConf job = new JobConf();
    job.setMapperClass(MapperClass.class);
    job.setNumReduceTasks(0);
    job.setNumMapTasks(1);
    job.set(SLEEP_SECS, args[0]);

    JobClient.runJob(job);
  }
}

最後更新:2016-11-24 11:23:47

  上一篇:go join示例__示例程序_MapReduce_大數據計算服務-阿裏雲
  下一篇:go unique示例__示例程序_MapReduce_大數據計算服務-阿裏雲