【发布时间】:2016-07-13 18:31:20
【问题描述】:
我正在使用 Hadoop 开发一个 mapreduce 项目。我目前有 3 个连续的工作。
我想使用 Hadoop 计数器,但问题是我想在第一个作业中进行实际计数,但在第三个作业的减速器中访问计数器值。
我怎样才能做到这一点?我应该在哪里定义enum?我需要通过它扔第二份工作吗?由于我还找不到任何东西,因此查看一些代码示例也会有所帮助。
注意:我使用的是 Hadoop 2.7.2
编辑:我已经尝试过here 解释的方法,但没有成功。我的情况不同,因为我想从不同的工作访问计数器。 (不是从映射器到减速器)。
我尝试做的事情: 第一份工作:
public static void startFirstJob(String inputPath, String outputPath) throws IOException, ClassNotFoundException, InterruptedException {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "wordCount");
job.setJarByClass(WordCount.class);
job.setMapperClass(WordCountMapper.class);
job.setCombinerClass(WordCountReducer.class);
job.setReducerClass(WordCountReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);
job.setInputFormatClass(SequenceFileInputFormat.class);
job.setOutputFormatClass(SequenceFileOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(inputPath));
FileOutputFormat.setOutputPath(job, new Path(outputPath));
job.waitForCompletion(true);
}
在不同的类中定义了计数器枚举:
public class CountersClass {
public static enum N_COUNTERS {
SOMECOUNT
}
}
试图读取计数器:
Cluster cluster = new Cluster(context.getConfiguration());
Job job = cluster.getJob(JobID.forName("wordCount"));
Counters counters = job.getCounters();
CountersClass.N_COUNTERS mycounter = CountersClass.N_COUNTERS.valueOf("SOMECOUNT");
Counter c1 = counters.findCounter(mycounter);
long N_Count = c1.getValue();
【问题讨论】:
-
我认为在 reduce 工作中使用计数器不是一个好主意。见stackoverflow.com/questions/8009802/…
-
是的,我已经看到了,我尝试了这种方法。但在这种情况下,他希望将计数器放在减速器内(相同的工作)。这和我的情况不一样。
标签: java hadoop mapreduce counter