如何在触发java代码时设置hadoop作业的优先级?

时间:2012-03-18 20:29:22

标签: java hadoop

这就是我的求职者的样子。如何在触发此作业时设置低优先级?

public int run(String[] args) throws Exception {
    this.initJob();
    Path outputPath = new Path(args[2]);
    FileInputFormat.setInputPaths(job, args[0]);
    FileOutputFormat.setOutputPath(job, outputPath);

    job.getConfiguration().set("FREQUENCY", args[3]);
    job.getConfiguration().set("TIMEZONE", args[4]);

    boolean rc = job.waitForCompletion(true);
    if (rc) {
        return 0;
    }
    return 1;
}
public void initJob() throws IOException {
    job = new Job(getConf(), "Stats Data Cruncher");
    job.setMapOutputKeyClass(Text.class);       
    job.setMapOutputValueClass(Text.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(NullWritable.class);
    Job.setInputFormatClass(LzoTextInputFormat.class);  

    job.setJarByClass(JobRunner.class);
    job.setMapperClass(StatsMapper.class);
    job.setCombinerClass(StatsCombiner.class);        
    job.setReducerClass(StatsReducer.class);
}

这条线是否有效设置LOW优先级?

job.getConfiguration().set("PRIORITY", "LOW");

2 个答案:

答案 0 :(得分:5)

您可以使用三种方法来设置工作优先级:

  1. 在xml配置文件中设置用户的作业优先级。
  2. 使用Hadoop命令设置您的工作:

    hadoop job -set-priority

  3. 在java代码中,您可以在配置中设置作业优先级:

    conf.set(“mapred.job.priority”,JOBPRIORITY.toString());

  4. JOBPRIORITY的值可能是:

    JobPriority.VERY_HIGH

    JobPriority.HIGH

    JobPriority.NORMAL

    JobPriority.LOW

    JobPriority.VERY_LOW

答案 1 :(得分:3)

“mapred.job.priority”是您要查找的属性。

您可以在配置中设置此项:

Configuration conf = new Configuration();
// set the priority to VERY_HIGH
conf.set("mapred.job.priority", JobPriority.VERY_HIGH.toString());