为此,你最好有一个减速器。
为了保证所有的号码来获得相同的减速机,你必须做两件事情:
- :发射的映射
- 设置reduce任务为零的所有输入值相同的密钥。
您map()
方法可能看起来像以下:
@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
context.write(new Text("MyAwesomeKey"), key); // assuming that your number is being read in the key
}
在你Reduce
类,有一个属性max
,是这样的: Long max
而且reduce()
方法可能看起来像以下:
@Override
public void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
context.write(new Text("MyAwesomeKey"), key); // assuming that your number is being read in the key
}
然后覆盖run()
也为我们覆盖reduce()
:
public void run(Context context) throws IOException, InterruptedException {
setup(context);
while (context.nextKey()) {
reduce(context.getCurrentKey(), context.getValues(), context);
}
context.write(new LongWritable(max),new Text("")); // write the max value
cleanup(context);
}
要设置减少任务之一,请执行下列操作在你的工作的run()
,注意,这是由上述run()
不同:
job.setNumReduceTasks(1);
注意:以上代码均遵循新的mapreduce API,我相信使用旧的mapred API,我们将无法在减速机完成作业后获得单点挂钩,因为我们可以通过重写Reducer的run()
来完成。
非常感谢你的回复。我会努力工作,我会让你知道的。谢谢。 – user2085189 2013-02-20 00:48:26