hive 参数调优

转载:

https://blog.csdn.net/renzhixin1314/article/details/70496325

Map Reduce数量相关

数据分片大小 (分片的数量决定map的数量) 
计算公式: splitSize = Math.max(minSize, Math.min(maxSize, blockSize))

set mapreduce.input.fileinputformat.split.maxsize=750000000;

单个reduce处理的数据量 (影响reduce的数量) 
计算公式: Max(1, Min(hive.exec.reducers.max [1099], ReducerStage estimate/hive.exec.reducers.bytes.per.reducer)) x hive.tez.max.partition.factor

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

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

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

执行计划相关

hive执行引擎 mr/tez/spark

set hive.execution.engine=mr;

调整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://dmtolpeko.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;

向量化计算 
https://cwiki.apache.org/confluence/display/Hive/Vectorized+Query+Execution 
如果开启, sum(if(a=1,1,0))这样的语句跑不过

set hive.vectorized.execution.enabled=false; 
set hive.vectorized.execution.reduce.enabled=false; 
set hive.vectorized.groupby.checkinterval=4096; 
set hive.vectorized.groupby.flush.percent=0.1; 
动态分区相关

hive0.13有个bug, 开启这个配置会对所有字段排序

set hive.optimize.sort.dynamic.partition=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相关

https://orc.apache.org/docs/hive-config.html

如果开启将会在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;

发布了355 篇原创文章 · 获赞 84 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/qq_43193797/article/details/92119091
今日推荐