これは、map reduce ステップ内での書き込み可能な変数と割り当てのパフォーマンスに関する質問です。レデューサーは次のとおりです。
static public class MyReducer extends Reducer<Text, Text, Text, Text> {
@Override
protected void reduce(Text key, Iterable<Text> values, Context context) {
for (Text val : values) {
context.write(key, new Text(val));
}
}
}
または、これはパフォーマンス面で優れています:
static public class MyReducer extends Reducer<Text, Text, Text, Text> {
private Text myText = new Text();
@Override
protected void reduce(Text key, Iterable<Text> values, Context context) {
for (Text val : values) {
myText.set(val);
context.write(key, myText);
}
}
}
Hadoop Definitive Guide では、すべての例が最初の形式になっていますが、それが短いコード サンプルのためなのか、より慣用的なためなのかはわかりません。