当一些键集有太多值时,如何平衡reducer?

h79rfbju  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(276)

由于数据不均衡,按键(must)聚类时,有些键集的数据太多,有些键集的数据很少。在这种情况下我怎样才能保持平衡?我已经检查过输入采样器了,它能用吗?

ivqmmu1c

ivqmmu1c1#

您可以实现自定义哈希分区器,这样您就可以将频率更高的键发送到一个reducer,并将频率更低的所有其他键发送到其他reducer。

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;

        }
    }

相关问题