2

在 Hive 中,我经常做如下查询:

select columnA, sum(columnB) from ... group by ...

我阅读了一些 mapreduce 示例,一个 reducer 只能产生一个键。看来reducer 的数量完全取决于columnA 中的键数。

因此,为什么 hive 可以手动设置减速器的数量?

如果 columnA 中有 10 个不同的值,并且我将 reducer 的数量设置为2,会发生什么?每个reducer会重复使用5次吗?

如果 columnA 中有 10 个不同的值,并且我将 reducer 的数量设置为20,会发生什么?hive 只会生成 10 个减速器?

4

1 回答 1

0

通常你不应该手动设置减速器的确切数量。改用bytes.per.reducer

--The number of reduce tasks determined at compile time
--Default size is 1G, so if the input size estimated is 10G then 10 reducers will be used
set hive.exec.reducers.bytes.per.reducer=67108864; 

如果要限制作业缩减器对集群的使用,可以设置此属性:hive.exec.reducers.max

如果您在 Tez 上运行,如果设置了此属性,则在执行时 Hive 可以动态设置减速器的数量:

set hive.tez.auto.reducer.parallelism = true;

在这种情况下,最初启动的减速器的数量可能会更大,因为它是根据大小估算的,在运行时可以删除额外的减速器。

一个 reducer 可以处理多个 key,这取决于数据大小和 bytes.per.reducer 和 reducer 限制配置设置。在您的示例中查询的情况下,相同的键将传递给同一个减速器,因为每个减速器容器都是独立运行的,并且所有具有特定键的行都需要传递给单个减速器才能计算该键的计数。

mapreduce.job.reducers=N额外的 reducer可以被强制(但是无论如何都会安排这样的减速器并分配容器,所以最好不要强制使用额外的减速器并保持统计信息新鲜以便更好地估计。

于 2020-06-16T12:58:31.580 回答