由于数据不是很均衡,按key(must)聚类时,有的key集数据多,有的少。在这种情况下我该如何平衡? 我已经研究了 InputSampler,它会起作用吗?
最佳答案
您可以实现自定义哈希分区器,这样您就可以将更高频率的键发送到一个缩减器,而将所有其他键以更低的频率发送到其他缩减器。
public static class AgePartitioner extends Partitioner<Text, Text> {
@Override
public int getPartition(Text key, Text value, int numReduceTasks) {
//we have more keys in this range so we want to sent them to one reducer
if(key >20 && key <=30){
return 1 ;
}
else
return 0;
}
}
关于hadoop - 当某些键集的值过多时如何平衡 reducer ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29689651/