hive查询的时候,导致服务器负载过高,load值飙升,服务器CPU是8个,按理说load不超过8,都应算ok的,但是,hive在部署完后没有调参,导致在执行过程中,load值达到了7.8以上,服务器连接出现问题,因此想到了调参,现在整理如下:
本次查询所用测试语句为:
select util_lnadw21ifj1579078492403.e2467e8ab37945a3869c6d3093d2c399,util_lnadw21ifj1579078492403.1cb0cb4bda2546f0a230d1955ff0d7a4,util_lnadw21ifj1579078492403.c690536676184df9a347c76c5c575661 from (select util_191pm71579078361630.e2467e8ab37945a3869c6d3093d2c399,util_191pm71579078361630.1cb0cb4bda2546f0a230d1955ff0d7a4,util_191pm71579078361630.c690536676184df9a347c76c5c575661,util_191pm71579078361630.f081b7ce95ef4e84b4d7282bc0c5e3f6 from (select data_oy3efaueda1579078258016.e2467e8ab37945a3869c6d3093d2c399,data_oy3efaueda1579078258016.1cb0cb4bda2546f0a230d1955ff0d7a4,data_oy3efaueda1579078258016.c690536676184df9a347c76c5c575661,data_oy3efaueda1579078258016.f081b7ce95ef4e84b4d7282bc0c5e3f6 from (select data_oy3efaueda1579078258016.name as e2467e8ab37945a3869c6d3093d2c399,data_oy3efaueda1579078258016.eud as 1cb0cb4bda2546f0a230d1955ff0d7a4,data_oy3efaueda1579078258016.salary as c690536676184df9a347c76c5c575661,data_oy3efaueda1579078258016.destination as f081b7ce95ef4e84b4d7282bc0c5e3f6 from test01.employee data_oy3efaueda1579078258016) data_oy3efaueda1579078258016 inner join(select data_diskmvki1579078266957.name as 3218b1512ecd457594d59dda6638392c,data_diskmvki1579078266957.eud as 443f2b8ea393492689720d38fbddfed1,data_diskmvki1579078266957.destination as 92eb60bfeb9041fb910c18d1fc9612ef from test01.employee_temp data_diskmvki1579078266957) data_diskmvki1579078266957 on data_oy3efaueda1579078258016.e2467e8ab37945a3869c6d3093d2c399=data_diskmvki1579078266957.3218b1512ecd457594d59dda6638392c) util_191pm71579078361630 where util_191pm71579078361630.c690536676184df9a347c76c5c575661='45000') util_lnadw21ifj1579078492403 where util_lnadw21ifj1579078492403.1cb0cb4bda2546f0a230d1955ff0d7a4='1201';
整理hive参数如下:
================================================================================
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://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