我認爲你的問題在於閱讀reduce()中的文件。您應該閱讀configure()(使用舊API)或setup()(使用新API)中的文件。因此,對於每一個減速將只讀取一次,而不是讀它爲每個輸入組到減速機(基本上,每次調用減少方法)
您可以編寫類似: 使用新的MapReduce API(ORG .apache.hadoop.mapreduce *) -
public static class ReduceJob extends Reducer<Text, Text, Text, Text> {
...
Path file1;
Path file2;
...
@Override
protected void setup(Context context) throws IOException, InterruptedException {
// Get the file from distributed cached
file1 = DistributedCache.getLocalCacheFiles(context.getConfiguration())[0];
file2 = DistributedCache.getLocalCacheFiles(context.getConfiguration())[1];
// parse the file and get it's data in-memory for use in reduce method, probably in some ArrayList or HashMap.
}
@Override
protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException,
InterruptedException {
...
}
}
使用舊的mapred API(org.apache.hadoop.mapred *) -
public static class ReduceJob extends MapReduceBase implements Reducer<Text, Text, Text, Text> {
...
Path file1;
Path file2;
...
@Override
public void configure(JobConf job) {
// Get the file from distributed cached
file1 = DistributedCache.getLocalCacheFiles(job)[0]
file2 = DistributedCache.getLocalCacheFiles(job)[1]
...
// parse the file and get it's data in-memory for use in reduce method, probably in some ArrayList or HashMap.
}
@Override
public synchronized void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output,
Reporter reporter) throws IOException {
...
}
}