Hive 分区场景及其对性能的影响

Hive partition scenario and how it impacts performance

我想询问有关配置单元分区数以及它们将如何影响性能的问题。

让我用一个真实的例子来反映这一点;

我有一个外部 table,预计每天有来自多个来源的大约 5 亿行,它应该有 5 个分区列。

一天,这导致了 250 个分区,预计 1 年的保留将达到 75K 左右。我认为这是一个巨大的数字,因为当我检查时,hive 可以达到 10K,但在那之后性能会很差..(有人告诉我每个 table 分区不应超过 1K)。

主要是 select 来自这个 table

的查询

其中 50% 应使用准确的分区顺序.. 25% 应仅使用 1-3 个分区而不使用其他 2 个。 25% 仅使用第一个分区

那么您认为即使留存 1 个月,这种方法是否可行?或者只有开始日期就足够了。假设其他 4 列呈正态分布(假设 500M/250 个分区,每个分区我们应该有 2M 行)。

我会选择 3 个分区列,因为这将 a) 与大约 50% 的查询配置文件完全匹配,并且 b) 大幅减少(修剪)其他 50% 的扫描分区数。同时,您不会被迫增加 Hive MetaStore (HMS) 堆内存并增强 HMS 后端数据库以高效地处理 250 x 364 = 91,000 个分区。

自引入 10K 限制以来,HMS 中的分区相关操作得到了极大的改进。请参阅 JIRA HIVE-13884 示例,它提供了保持低数字的动机,并描述了处理高数字的方式:

The PartitionPruner requests either all partitions or partitions based on filter expression. In either scenarios, if the number of partitions accessed is large there can be significant memory pressure at the HMS server end. ... PartitionPruner [can] first fetch the partition names (instead of partition specs) and throw an exception if number of partitions exceeds the configured value. Otherwise, fetch the partition specs.

请注意,分区规格(如上所述)和收集的统计数据每个分区(始终建议拥有以进行高效查询),构成了 HMS 应该存储和缓存的大部分数据以获得良好的性能。