[Hive]Hive调优:让任务并行执行

业务背景

extract_trfc_page_kpi的hive sql如下:

mapred.reduce.tasks=overwrite table pms.extract_trfc_page_kpi partition(ds=’$yesterday’)select distinctpage_type_id,pv,uv,’$yesterday’ update_time from(–针对PC、H5selectpage_type_id,sum(pv) as pv,sum(uv) as uvfrom dw.rpt_trfc_page_kpipage_type_id union all–PC搜索页特殊处理page_type_id,sum(pv) as pv,sum(uv) as uvfrom dw.rpt_trfc_page_kpipage_type_id in (51, 52)union all–针对APPselecta.page_type_id,sum(pv) as pv,sum(uv) as uvfrom dw.rpt_trfc_page_kpi a(select distinctpage_type_id,old_page_type_idfrom tandem.mobile_backend_page_url_rulewhere is_delete = 0) b on (a.page_type_id = b.old_page_type_id)a.page_type_id ) t;

上面的sql中存在两个union all操作,顺序执行下来的话,需要耗时20分钟。

优化策略

分析以上的sql,其中union all前后的三个查询操作并无直接关联,因此没有必要顺序执行,因此优化的思路是让这三个查询操作并行执行,hive提供了如下参数实现job的并行操作:

// 开启任务并行执行set hive.exec.parallel=true;// 同一个sql允许并行任务的最大线程数set hive.exec.parallel.thread.number=8;方案一

在执行sql时加上上面的两个hive参数,如:

mapred.reduce.tasks=hive.overwrite table pms.extract_trfc_page_kpi partition(ds=’$yesterday’)select distinctpage_type_id,pv,uv,’$yesterday’ update_time from(–针对PC、H5selectpage_type_id,sum(pv) as pv,sum(uv) as uvfrom dw.rpt_trfc_page_kpipage_type_id union all–PC搜索页特殊处理page_type_id,sum(pv) as pv,sum(uv) as uvfrom dw.rpt_trfc_page_kpipage_type_id in (51, 52)union all–针对APPselecta.page_type_id,sum(pv) as pv,sum(uv) as uvfrom dw.rpt_trfc_page_kpi a(select distinctpage_type_id,old_page_type_idfrom tandem.mobile_backend_page_url_rulewhere is_delete = 0) b on (a.page_type_id = b.old_page_type_id)a.page_type_id ) t;方案二

在hive-site.xml中进行设置,查看当前版本hive的配置参数:

hive> set -v;…hive=falsehive.exec.parallel=falsehive=8hive=orghive=truehive=truehive=1000000000hive=999hive.exec.rowoffset=falsehive.exec.scratchdir=/tmp/hive-pmshive=falsehive=100000hive=falsehive=true…

这些参数是配置在$HIVE_HOME/conf/hive-site.xml中的,,现在在这个配置文件中加入:

>true>>

重新启动hive,看到刚刚配置的参数已经生效了:

hive> set -v;…hive=falsehive=falsehive.exec.parallel=truehive=16hive=orghive=truehive=truehive=1000000000hive=999hive.exec.rowoffset=falsehive.exec.scratchdir=/tmp/hive-pmshive=false…结论

经过测试,添加了这两个参数以后,extract_trfc_page_kpi脚本执行时间从耗时20分钟,优化为耗时3分钟。

要做一个积极勇敢乐观的追梦人,永远不说消极的话,

[Hive]Hive调优:让任务并行执行

相关文章:

你感兴趣的文章:

标签云: