hive mapreduce reducer 调优

本文详细解析Hive中三个关键参数:hive.exec.reducers.bytes.per.reducer、mapred.reduce.tasks和hive.exec.reducers.max,帮助理解如何通过这些参数优化Reducer的性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


hive参数配置详情可查官方文档: Hive Configuration+Properties

本文针对 reducer 调优,主要涉及一下三个参数:

hive.exec.reducers.bytes.per.reducer

Default Value: 1,000,000,000 prior to Hive 0.14.0; 256 MB (256,000,000) in Hive 0.14.0 and later
Added In: Hive 0.2.0; default changed in 0.14.0 with HIVE-7158 (and HIVE-7917)
Size per reducer. The default in Hive 0.14.0 and earlier is 1 GB, that is, if the input size is 10 GB then 10 reducers will be used. In Hive 0.14.0 and later the default is 256 MB, that is, if the input size is 1 GB then 4 reducers will be used.

说明:每个reducer能够处理的文件大小。这个参数控制一个job会有多少个reducer来处理,依据的是输入文件的总大小。官方默认值:1G

查看配置的默认值:

hive> set hive.exec.reducers.bytes.per.reducer;
hive.exec.reducers.bytes.per.reducer=1024000000

临时调参:

hive> set hive.exec.reducers.bytes.per.reducer=15364000000;
hive>  set hive.exec.reducers.bytes.per.reducer;
hive.exec.reducers.bytes.per.reducer=15364000000

mapred.reduce.tasks

  • Default Value: -1
  • Added In: Hive 0.1.0
    The default number of reduce tasks per job. Typically set to a prime close to the number of available hosts. Ignored when mapred.job.tracker is “local”. Hadoop set this to 1 by default, whereas Hive uses -1 as its default value. By setting this property to -1, Hive will automatically figure out what should be the number of reducers.

含义:设置每个job的reduce数。官方默认值为:-1

查看配置的默认值:

hive> set mapred.reduce.tasks;
mapred.reduce.tasks=-1

临时调参:

hive> set mapred.reduce.tasks=100;
hive> set mapred.reduce.tasks;
mapred.reduce.tasks=100

hive.exec.reducers.max

  • Default Value: 999 prior to Hive 0.14.0; 1009 in Hive 0.14.0 and later
  • Added In: Hive 0.2.0; default changed in 0.14.0 with HIVE-7158 (and HIVE-7917)
    Maximum number of reducers that will be used. If the one specified in the configuration property mapred.reduce.tasks is negative, Hive will use this as the maximum number of reducers when automatically determining the number of reducers.

含义:设置最大的reduce数。如果mapreduce计算的reduce数超过设定值的值,则取设置的值。

查看配置的默认值:

hive> set hive.exec.reducers.max;
hive.exec.reducers.max=1099

临时调参:

hive> set hive.exec.reducers.max=999;
hive> set hive.exec.reducers.max;
hive.exec.reducers.max=999

以上所有set的值,都只是临时调整,不会改变配置文件中的配置。当你重新打开hive会话,查看相应的配置就一目了然了。

我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=3ckgexxns8g0o

<think>嗯,用户想了解Hive on MapReduce的性能最佳实践和参数配置。我需要结合他们提供的引用内容来整理答案。首先,Hive通常涉及多个方面,比如数据压缩、资源分配、动态分区和查询化等。让我仔细看看用户提供的引用内容。 引用[1]提到了中间数据的压缩,设置hive.exec.compress.intermediate为true,这样可以减少数据传输量,提升性能。中间文件压缩很重要,尤其是在多个MapReduce作业之间传输数据的时候。可能需要提到使用哪种压缩算法,比如Snappy或LZO,因为它们压缩和解压速度快。 引用[2]和[3]虽然主要是关于Hive on Spark的参数,但里面提到的一些思路可能也适用于MapReduce。比如动态分配Executor,但在MapReduce里可能对应的是整mapperreducer的数量。不过MapReduce的资源管理可能更多依赖于YARN的配置,比如mapreduce.map.memory.mb和mapreduce.reduce.memory.mb这些参数。需要确认这些参数是否属于Hive的一部分。 引用[4]提到动态分区的设置,需要将hive.exec.dynamic.partition.mode设为nonstrict。动态分区在处理大量分区时能提升效率,避免静态分区的限制。另外,可能还需要设置hive.exec.max.dynamic.partitions来控制最大分区数,防止过多分区导致的问题。 接下来,用户的问题是关于MapReduce的,所以需要重点整理与MapReduce相关的参数。比如: 1. 压缩设置:中间数据和最终输出的压缩,如hive.exec.compress.output和hive.exec.compress.intermediate,以及压缩编解码器的选择。 2. 整mapperreducer的数量:MapReduce中可以通过mapreduce.job.maps和mapreduce.job.reduces来设置,但通常Hive会自动计算,但有时候手动整可能更好。比如减少reducer数量过大导致的小文件问题。 3. 资源分配:整每个task的内存,避免OOM错误,如mapreduce.map.memory.mb和mapreduce.reduce.memory.mb,以及JVM堆大小的设置。 4. 动态分区和分桶:合理使用动态分区和分桶技术,化数据存储和查询效率。 5. 数据倾斜处理:比如通过hive.groupby.skewindata来应对group by时的数据倾斜。 6. 并行执行:设置hive.exec.parallel为true,允许多个阶段并行执行。 7. 合并小文件:输入阶段合并小文件,输出阶段也合并,减少任务数。 可能还需要提到一些其他参数,比如hive.optimize.sort.dynamic.partition在插入动态分区时的排序化,或者使用Tez引擎替代MapReduce,不过用户明确问的是MapReduce,所以Tez可能不在讨论范围内。 另外,需要注意参数设置的上下文,比如是在hive-site.xml中设置,还是在会话级别通过SET命令设置。引用中提到的hive.exec.compress.intermediate就是一个例子,用户需要知道在哪里配置这些参数。 可能还要提到监控和诊断工具,比如查看作业的Counter数据,分析哪些阶段耗时较长,从而针对性化。 总结起来,结构应该分为几个部分:压缩化、资源参数整、任务并行度、数据存储化、动态分区配置、处理数据倾斜、小文件合并等。每个部分给出具体参数和推荐值,并引用对应的引用来支持。例如,中间压缩引用[1],动态分区引用[4],资源参数参考引用[3]中的思路,虽然引用[3]是关于Spark的,但类似的资源管理原则可能适用。 最后生成相关问题的时候,要确保问题覆盖的不同方面,比如压缩配置、资源参数、动态分区使用、数据倾斜处理等。</think>### Hive on MapReduce 性能最佳实践 #### 一、中间数据压缩化 1. **启用中间文件压缩** 设置`hive.exec.compress.intermediate=true`,可减少MapReduce作业间的数据传输量,提升I/O效率[^1]。建议使用**Snappy**或**LZO**压缩算法(需Hadoop支持),平衡压缩率与速度: ```sql SET hive.exec.compress.intermediate=true; SET mapred.map.output.compression.codec=org.apache.hadoop.io.compress.SnappyCodec; ``` 2. **输出结果压缩** 启用`hive.exec.compress.output`压缩最终输出文件: ```sql SET hive.exec.compress.output=true; SET mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec; ``` --- #### 二、资源分配与任务并行度 1. **Mapper/Reducer资源配置** - **内存分配**:通过YARN参数控制单个任务资源,避免OOM: ```sql SET mapreduce.map.memory.mb=4096; -- 单个Map Task内存 SET mapreduce.reduce.memory.mb=8192; -- 单个Reduce Task内存 ``` - **JVM重用**:减少任务启动开销: ```sql SET mapreduce.job.jvm.numtasks=10; -- 单个JVM运行的任务数 ``` 2. **动态Reducer数量** Hive默认根据数据量计算Reducer数量,可通过`hive.exec.reducers.bytes.per.reducer`整: ```sql SET hive.exec.reducers.bytes.per.reducer=256000000; -- 每个Reducer处理256MB数据 ``` --- #### 三、数据存储与查询化 1. **动态分区配置** 避免全表扫描,启用动态分区并限制最大分区数[^4]: ```sql SET hive.exec.dynamic.partition.mode=nonstrict; SET hive.exec.max.dynamic.partitions=10000; ``` 2. **合并小文件** - **输入阶段合并**:减少Map任务数: ```sql SET hive.input.format=org.apache.hadoop.hive.ql.io.CombineHiveInputFormat; ``` - **输出阶段合并**:避免生成过多小文件: ```sql SET hive.merge.mapfiles=true; -- Map-only作业输出合并 SET hive.merge.mapredfiles=true; -- MapReduce作业输出合并 SET hive.merge.size.per.task=256000000; -- 合并文件阈值 ``` 3. **数据倾斜处理** - **Group By倾斜化**:启用`hive.groupby.skewindata`: ```sql SET hive.groupby.skewindata=true; -- 生成两个MR Job分散负载 ``` - **Join倾斜处理**:使用Map Join或过滤倾斜键值: ```sql SET hive.auto.convert.join=true; -- 自动转为Map Join(小表<25MB) ``` --- #### 四、高级参数 | 参数 | 作用 | 推荐值 | |------|------|--------| | `hive.exec.parallel` | 开启Stage并行执行 | `true` | | `hive.optimize.sort.dynamic.partition` | 动态分区插入时排序化 | `true` | | `mapreduce.reduce.shuffle.input.buffer.percent` | Reduce阶段Shuffle缓冲区占比 | `0.7` | ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值