09分布式数据仓库 HIVE -- HIVE优化
来源:互联网 发布:随机种子知乎 编辑:程序博客网 时间:2024/06/03 12:30
HIVE执行流程
explain extended select city,count(1) from user group by city; //查看HQL对应的mapreduce流程树
1表的优化
1:表分区(例如:日志按天存放)
2:表分桶
2HQL优化
1: join优化
set hive.optimize.skewjoin=true;数据倾斜
set hive.skewjoin.key=5000;//当join key超过5000时,为key加上随机数启动另一个job来处理。
mapjoin
bucket join
join案例(join后的where是在reduce端执行,map带来了更多的数据,所以把过滤放到map端。)
优化前
select u.id,u.name from user u join student s on u.id=s.id where u.sex = 'boy';
优化后
select u.id,u.name from (select id name from user where sex = 'boy') u join student s on u.id = s.id;
2:groupby优化
set hive.optimize.skewindata=true;数据倾斜
set hive.groupby.mapaggr.checkinterval=5000;//当group key超过5000时,为key加上随机数启动另一个job来处理。
groupby优化案例
优化前(count 和distinct集中在reduce端执行,单机压力大。)
select count(distinct city) from user;
优化后1(子表查询在多个端reduce执行)
set hive.mapred.tasks=5;
select count(1) from (select distinct city from user) u;
优化后2()
select count(3) from (select city from user group by city) u;
group by 优化案例2
优化前
select id,sum(money),count(distinct age),count(distinct grade) from user;
优化后
select id,sum(money) as m,count(age) as a ,count(grade) as g from
(select id,0 as m,age,null as g from user group by id,age
union all select id,0 as m,null as a,grade from user group by id,grade
union all select id,money,null as a,null as g from user
) u group by id
3 mapreduce优化
1:相似的数据尽量放到一起,尽量让mapreduce的执行过程在本机。减少网络传输耗费的时间和资源。
2:开启job并行化,同时开启无依赖的job任务。
set hive.exec.parallel = true;
set hive.exec.parallel.thread.number = 10;
select name from
(select count(city)) as cn from city union all select count(class) as csn from school) cs;
后两个子查询是不相互依赖的job,可以并行执行。
4 本地化执行
5 合并小文件
set hive.input.format=org.apache.hadoop.hive.ql.io.CombineHiveInputFormat
set mapred.max.split.size
set hive.merge.smallfiles.avgsize=256000000;//mapreduce输出的文件低于该值时,会启动一个新的job来合并文件。
set hive.merge.size.per.task=64000000; //合并之后的文件大小。
6 jvm重用,job优化
set mapreduce.job.reuse.jvm.num.tasks=10;
7 job和job直接的数据压缩
set hive.exec.compress.intermediate=true;
set hive.intermediate.compression.codec=org.apache.hadoop.io.compress.SnappyCodec;
set hive.intermediate.compression.type=BLOCK;
8 job查询结果输出压缩
set hive.exec.compress.outer=true;
set mapred.output.compression.coder=org.apache.hadoop.io.compress.GzipCoder;
set mapred.output.compression.type=BLOCK;
9 map优化
set mapred.map.tasks=25;
1:default_num=total_size/block_size;
2:goal_num=mapred.map.tasks;
3:split_size=max(mapred.min.split.size,block_size);
split_num= total_size/split_size;
最终compute_map_num=min(split_num,max(default_num,goal_num));
想增加map个数,设置mapred.map.tasks=20;//20越大,map个数越多。
想减少map个数,设置mapred.min.split.size=20;// 20越大,map个数月小;
案例1:如果size巨大,不是一堆小文件。
则需要减少map的个数。
案例2:输入文件是好多个小文件,使用CombineFileInputFormat合并小文件。简介的减少mapper的个数。
在map端做一次初步聚合,set hive.map.aggr=true;
推测执行
set mapred.map.tasks,speculative.execution; //启动两个job,哪个job先完成HQL查询,则用这个结果,同时删除另一个job;
10 shuffle优化
map端
io.sort.mb
io.sort.spill.percent
min.num.spill.for.combine
io.sort.factor
io.sort.record.percent
reduce端
mapred.reduce.parallel.copies
mapred.reduce.copu.backoff
io.sort.factor
mapred.job.shuffle.input.buffer.percent
mapred.job.reduce.input.buffer.percent
11 reduce优化
需要reduce的查询有,聚合函数,高级查询。order by 只有一个reduce。唯一一个比较鸡勒的。
推测执行,2选1即可
mapred.reduce.tasks.speculative,execution //
hive.mapred.reduce.tasks.speculative.execution //
set mapred.reduce.tasks=10;// 直接生效,不需要公式
hive.exec.reducers.max
hive.exec.reduces.bytes.per.reducer
- 09分布式数据仓库 HIVE -- HIVE优化
- 07分布式数据仓库 HIVE -- 函数
- Hive - 数据仓库的性能优化
- Hive-数据仓库
- HIVE在腾讯分布式数据仓库实践
- 01分布式数据仓库 HIVE -- 数据类型-文件格式
- 04分布式数据仓库 HIVE -- 导出分析结果
- 05分布式数据仓库 HIVE -- 分区表的操作
- 08分布式数据仓库 HIVE -- UDF和UDAF
- 11分布式数据仓库 HIVE -- HIVE案例实战2 SLA
- 数据仓库--Hive之常用优化方法
- 数据仓库中的SQL性能优化 - Hive篇
- 02分布式数据仓库 HIVE -- 表的相关操作
- 03分布式数据仓库 HIVE -- 数据的相关操作
- hive(数据仓库工具)
- 数据仓库工具--Hive
- 数据仓库工具:Hive
- Hive(一个数据仓库)
- cloud control 12c Patch 18090046
- C#中控件的tag属性
- 有用的链接
- 针对表单的CSS3伪类选择器
- 各大浏览器 CSS3 和 HTML5 兼容速查表
- 09分布式数据仓库 HIVE -- HIVE优化
- C#窗口移动特效,Download()
- 单独编译gd.so
- eclipse选择jdk启动的问题
- iOS Bug(1)dyld: Symbol not found:并且 Expected in:
- further
- IOS/ANDROID/浏览器判断/屏幕尺寸
- 在linux下,对压缩包分卷处理
- 坚持(发表于2014-12-24 10:17)