0

Is it must that we have to set number of reducers to use custom partitioner ? Example : Word Count problem, want to get all the stop words count in one partition and remaining words count to go to different partition. If I set number of reducers to two and stop words to go to one partition and others to go to the next partition, it will work, but I am restricting the number of reducers to two(or N ), which I don't want. What is the best approach here? Or I have to calculate and set the number of reducers based on the size of the input to get the best performance?

4

1 回答 1

0

指定自定义分区器不会更改任何内容,因为分区数已提供给分区器:

int getPartition(KEY key, VALUE value, int numPartitions) 

如果您不设置分区器,HashPartitioner则使用 。它的实现很简单:

public int getPartition(K key, V value, int numReduceTasks) {
    return (key.hashCode() & Integer.MAX_VALUE) % numReduceTasks;
}

自定义分区器的设计取决于您。分区器的主要目标是避免偏差并将负载均匀分布在提供的分区数量上。对于一些小工作,可以决定只支持两个减速器,但如果你想让你的工作扩展,那么你必须设计你的工作来运行任意数量的减速器。

或者我必须根据输入的大小计算和设置减速器的数量以获得最佳性能?

这始终是您必须做的,并且与自定义分区器的使用无关。您必须设置 reducer 的数量,默认值为 1,Hadoop 不会为您计算此值。

如果您想向一个减速器发送停用词,向另一个减速器发送其他词,您可以执行以下操作:

public int getPartition(K key, V value, int numReduceTasks) {
    if (isStopWord(key) {
        return 0;
    } else {
        return ((key.hashCode() & Integer.MAX_VALUE) % (numReduceTasks - 1)) + 1;
    }
 }

但是,它很容易导致大的数据倾斜。第一个减速器将过载,并且比其他减速器需要更长的时间才能完成。在这种情况下,使用两个以上的减速器是没有意义的。

可能是XY 问题。我不确定您要问的是解决实际问题的最佳方法。

于 2014-09-08T20:25:55.033 回答