一、解決數據傾斜
1. 過濾掉null部分
key值存在大量空字段,會hash到同一reduce,造成reduce長尾,將null 值過濾掉
舉例: select user_id from logs where statdate = '20170815' where user_id is not null;
2. hive join傾斜:設置join skew參數解決
set hive.optimize.skewjoin = true;
set hive.skewjoin.key = skew_key_threshold (default = 100000);
3. hive group by distinct傾斜:設置skew參數
set hive.groupby.skewindata=true;
二、合理設置map和reduce的個數
1. 合理設置reduce的個數
set mapred.reduce.tasks = 15;
2. jvm重用
set Mapred.job.reuse.jvm.num.tasks = 10; (重用次數)
節約jvm 啓動的時間
3. job間並行執行
set hive.exec.parallel=true; 默認並行度爲 8,可以通過 hive.exec.parallel.thread.number參數調整
在有些情況下Job之間是可以並行的,典型的就是子查詢。
當需要執行多個子查詢union all或者join操作的時候,Job間並行就可以使用了。
例:如下可以並行的場景
select * from ( select count(*) from logs where log_date = 20170801 and item_id = 1 union all select count(*) from logs where log_date = 20170802 and item_id = 2 union all select count(*) from logs where log_date = 20170803 and item_id = 3 )t;