美文网首页
Hive参数优化实践参考1

Hive参数优化实践参考1

作者: liuzx32 | 来源:发表于2020-07-20 16:51 被阅读0次

Tez的Group管理

tez.grouping.min-size 默认50M
tez.grouping.max-size 默认1G

  1. 分组拆分大小的下限默认值为 50 MB分组;拆分大小的上限默认值为 1 GB
  2. 减小这两个参数可以改善延迟,增大这两个参数可以提高吞吐量。
  3. 例如,若要为数据大小 128 MB设置四个映射器任务,可将每个任务的这两个参数设置为 32 MB(33,554,432 字节。

Reduce Stage什么时候执行

tez.shuffle-vertex-manager.min-src-fraction
tez.shuffle-vertex-manager.max-src-fraction

  1. tez.shuffle-vertex-manager.min-src-fraction默认值为0.25
  2. tez.shuffle-vertex-manager.max-src-fraction默认值为2
  3. 这两个值效果一致,增加该值则reduce stage启动晚一些。减少该值则reduce stage启动早一些
  4. 举例:想让所有map都执行完才开始执行reduce,可以将这两个值都设置为1

Map Reduce数量相关

数据分片大小 计算公式 (分片的数量决定map的数量)

splitSize = Math.max(minSize, Math.min(maxSize, blockSize))
set mapreduce.input.fileinputformat.split.maxsize=750000000;

单个reduce处理的数据量 (影响reduce的数量)

set hive.exec.reducers.bytes.per.reducer=629145600;

tez将会根据Vertex的输出大小动态预估调整reduce的个数

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

最小的reduce个数的计算公式:

minReduces = min(hive.exec.reducers.max [1099], max((ReducerStage estimate/hive.exec.reducers.bytes.per.reducer),1)*hive.tez.min.partition.factor)

最大的reduce个数的计算公式:

maxReduces = min(hive.exec.reducers.max [1099], max((ReducerStage estimate/hive.exec.reducers.bytes.per.reducer),1)*hive.tez.max.partition.factor)

Hive执行引擎 mr/tez/spark

set hive.execution.engine=mr;
set hive.execution.engine=tez;
set hive.execution.engine=spark;

调整Join顺序,让多次Join产生的中间数据尽可能小,选择不同的Join策略

set hive.cbo.enable=true;

如果数据已经根据相同的key做好聚合,那么去除掉多余的map/reduce作业

set hive.optimize.reducededuplication=true;

如果一个简单查询只包括一个group by和order by,此处可以设置为1或2

set hive.optimize.reducededuplication.min.reducer=4;

Map Join优化, 不太大的表直接通过map过程做join

set hive.auto.convert.join=true;
set hive.auto.convert.join.noconditionaltask=true;

Map Join任务HashMap中key对应value数量

set hive.smbjoin.cache.rows=10000;

可以被转化为HashMap放入内存的表的大小(官方推荐853M)

set hive.auto.convert.join.noconditionaltask.size=894435328;

**map端聚合(跟group by有关), 如果开启, Hive将会在map端做第一级的聚合, 会用更多的内存

http://dmtolp**eko.com/2014/10/13/map-side-aggregation-in-hive/
开启这个参数 sum(1)会有类型转换问题
set hive.map.aggr=false;

所有map任务可以用作Hashtable的内存百分比, 如果OOM, 调小这个参数(官方默认0.5)

set hive.map.aggr.hash.percentmemory=0.5;

将只有SELECT, FILTER, LIMIT转化为FETCH, 减少等待时间

set hive.fetch.task.conversion=more;
set hive.fetch.task.conversion.threshold=1073741824;

聚合查询是否转化为FETCH

set hive.fetch.task.aggr=false;

如果数据按照join的key分桶,hive将简单优化inner join(官方推荐关闭)

set hive.optimize.bucketmapjoin= false;
set hive.optimize.bucketmapjoin.sortedmerge=false;

以下两个参数用于开启动态分区

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;

合并小文件

set hive.merge.mapfiles=true;
set hive.merge.mapredfiles=true;
set hive.merge.tezfiles=true;
set hive.merge.sparkfiles=false;
set hive.merge.size.per.task=536870912;
set hive.merge.smallfiles.avgsize=536870912;
set hive.merge.orcfile.stripe.level=true;

如果开启将会在ORC文件中记录metadata

set hive.orc.splits.include.file.footer=false;

ORC写缓冲大小

set hive.exec.orc.default.stripe.size=67108864;

新创建的表/分区是否自动计算统计数据

set hive.stats.autogather=true;
set hive.compute.query.using.stats=true;
set hive.stats.fetch.column.stats=true;
set hive.stats.fetch.partition.stats=true;

手动统计已经存在的表 (本次没做)

ANALYZE TABLE COMPUTE STATISTICS;
ANALYZE TABLE COMPUTE STATISTICS for COLUMNS;
ANALYZE TABLE partition (coll=”x”) COMPUTE STATISTICS for COLUMNS;

在order by limit查询中分配给存储Top K的内存为10%

set hive.limit.pushdown.memory.usage=0.1;

是否开启自动使用索引

set hive.optimize.index.filter=true;

获取文件块路径的工作线程数

set mapreduce.input.fileinputformat.list-status.num-threads=5;

如果自动分区数大于这个参数,将会报错

set hive.exec.max.dynamic.partitions=100000;
set hive.exec.max.dynamic.partitions.pernode=100000;


======================================================================

对比了上述参数,本次优化了以下内容:
hive> set hive.limit.pushdown.memory.usage;
hive.limit.pushdown.memory.usage=-1.0

hive> set hive.stats.fetch.column.stats;
hive.stats.fetch.column.stats=false

hive> set hive.merge.smallfiles.avgsize;
hive.merge.smallfiles.avgsize=16000000

hive> set hive.merge.tezfiles;
hive.merge.tezfiles=false

hive> set hive.exec.dynamic.partition.mode;
hive.exec.dynamic.partition.mode=strict

hive> set hive.auto.convert.join.noconditionaltask.size;
hive.auto.convert.join.noconditionaltask.size=10000000

hive> set hive.optimize.index.filter;
hive.optimize.index.filter=false

hive> set mapreduce.input.fileinputformat.list-status.num-threads;
mapreduce.input.fileinputformat.list-status.num-threads=1

hive> set hive.exec.max.dynamic.partitions;
hive.exec.max.dynamic.partitions=1000

hive> set hive.exec.max.dynamic.partitions.pernode;
hive.exec.max.dynamic.partitions.pernode=100

hive> set hive.map.aggr;
hive.map.aggr=true

这些都是hive默认的值,按照上述均作出了调整,目前和上述参数设置一致,再次执行查询语句,load稳定在5.5左右,如果让开发单独执行这条语句,load在2以下,目前看来参数是有效的

mapred.child.java.opts 这个参数我这里没有具体优化,这个参数是配置每个map或reduce使用的内存数量。默认的是200M。对于这个参数,我个人认为,如果内存是8G,CPU有8个核,那么就设置成1G就可以了。实际上,在map和reduce的过程中对内存的消耗并不大,但是如果配置的太小,则有可能出现”无可分配内存”的错误。所以,对于这个配置我总结了一个简单的公式:map/reduce的并发数量(总和不大于CPU核数)×mapred.child.java.opts < 该节点机器的总内存。当然也可以等于,不过有点风险而已。参考:https://blog.csdn.net/breakout_alex/article/details/89019803

本次优化参考链接:

https://blog.csdn.net/yu0_zhang0/article/details/81776459
https://blog.csdn.net/scgaliguodong123_/article/details/45477323
https://www.cnblogs.com/felixzh/p/8604188.html
https://blog.csdn.net/young_0609/article/details/84593316

这是精髓:

https://blog.csdn.net/qq_26442553/article/details/99438121
https://blog.csdn.net/qq_26442553/article/details/99693490
https://blog.csdn.net/qq_18838991/article/details/51819295

另外:MR的内存优化参考这篇:

https://blog.csdn.net/u014665013/article/details/80923044
https://www.jianshu.com/p/73d9ce671261

hive的存储,参考这篇:

https://blog.csdn.net/zyzzxycj/article/details/79267635
https://blog.csdn.net/zyzzxycj/article/details/79270051

小文件处理,参考这篇:

https://blog.csdn.net/u010010664/article/details/83105174

相关文章

  • Hive参数优化实践参考1

    Tez的Group管理 tez.grouping.min-size 默认50Mtez.grouping.max-s...

  • CentOS7.x优化

    同步时间 禁用SELinux 关闭防火墙 内核生产环境优化参数 参考1:CentOS内核参数优化参考 参考2:Ce...

  • hive参数优化

    目录 小文件处理的参数 数据倾斜参数 分区表参数 并行执行参数 代码块中的参数值都是cdh 5.7的默认值.查看h...

  • 配置Hive支持update

    配置 hive-site.xml配置参数(CDH的配置参考如下图)hive.support.concurrency...

  • hive 查询优化

    1、优化count的时间 调整hive.compute.query.using.stats 参数,这一在执行co...

  • Hive 企业使用优化一

    Hive优化之一fetch task。 优化场景, 1、当在hive中执行select * from emp全部查...

  • Hive优化之Hive的配置参数优化

    Hive是大数据领域常用的组件之一,主要用于大数据离线数仓的运算,关于Hive的性能调优在日常工作和面试中是经常涉...

  • Hive优化笔记

    1.hive参数优化 1.1 map个数优化 map的个数是如何决定的: 一个文件在执行数据处理的时候,被分成文件...

  • 数仓--Hive-面试之Hive优化策略

    Hive的优化策略大致分为:配置优化(hive-site.xml和hive-cli执行前配置)、表优化、hive数...

  • Hive优化的原则参考

    〇.Hive中部分优化参数 一. 本地模式(小任务) 需要满足以下条件: job的输入数据大小必须小于参数:hiv...

网友评论

      本文标题:Hive参数优化实践参考1

      本文链接:https://www.haomeiwen.com/subject/hnsykktx.html