全部产品
MaxCompute

sleep示例

更新时间:2017-06-07 13:26:11   分享:   

(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);
  }
}
本文导读目录
本文导读目录
以上内容是否对您有帮助?