1. 程式人生 > >hive 一些優化

hive 一些優化

環境 hive1.2.1 + hadoop2.6.0 一.mapjoin優化 原理:對於join操作,內連線中有一個表是小表,或者左連線時左表為小表時,自動將MR作業轉化為Map,即在map端進行資料join操作,而不是reduce端。在執行任務的本地,將小錶轉換為hashtable,然後上傳到叢集中,之後的每個map中都有全量的小表來直接進行join操作,從而跳過了shuffle階段,這種情況能夠適用部分資料傾斜的任務,以及提高了整體的效率。 經過測試,小表序列化為java hashtable需要的記憶體大約是小表資料量的10倍左右的記憶體(單列測試,每行為int型別) mapjoin日誌 Execution log at: /tmp/test/test_20150924105256_51743552-6005-4630-b054-96bb1d004b02.log 2015-09-24 10:53:00     Starting to launch local task to process map join;     maximum memory = 932184064
2015-09-24 10:53:03     Processing rows:     200000     Hashtable size:     199999     Memory usage:     156235088     percentage:     0.168
2015-09-24 10:53:03     Dump the side-table for tag: 1 with group count: 244027 into file: file:/tmp/test/369e0363-c6a9-4860-84a9-ea65525a1981/hive_2015-09-24_10-52-56_295_3688765404209462896-1/-local-10004/HashTable-Stage-4/MapJoin-mapfile01--.hashtable
2015-09-24 10:53:06     Uploaded 1 File to: file:/tmp/test/369e0363-c6a9-4860-84a9-ea65525a1981/hive_2015-09-24_10-52-56_295_3688765404209462896-1/-local-10004/HashTable-Stage-4/MapJoin-mapfile01--.hashtable (27460551 bytes)
2015-09-24 10:53:06     End of local task; Time Taken: 5.932 sec. Execution completed successfully
1.適用於內連線中有一張表是小表或者左連線時 set hive.auto.convert.join=true set hive.mapjoin.smalltable.filesize=100000000      ( hive1.2.1預設為25MB,修改為100MB) 適用示例語句: select a.dvc_id from tds_did_user_targ_mon a left outer join maptable b on a.dvc_id=b.dvc_id; 2.只適用於內連線中,除了第一個表之外的其他表是小表的情況,自動連線操作 set hive.auto.convert.join=true set hive.auto.convert.join.noconditionaltask.size=60000000;  (hive1.2.1預設為10MB,修改為60MB) set hive.auto.convert.join.noconditionaltask=true; 作用:當n-1個tables/partitions 的總量 小於 hive.auto.convert.join.noconditionaltask.size,join將會自動轉為一個mapjoin,而不是多個join
適用示例語句: select  a.dvc_id   from tds_did_user_targ_mon a join maptable b on a.dvc_id=b.dvc_id join maptable1 c on b.dvc_id=c.dvc_id; 上述語句將生成一個Map作業。 二. 其他引數調優 hive.exec.parallel=true;         hive.exec.parallel.thread.number=4;                     sql中的並行服務: hive.exec.compress.output=true;                hive中間結果啟動壓縮 hive.optimize.bucketmapjoin=true;            開啟bucket map join,測試這種型別的只有在bucket表才會有效。 hive.groupby.skewindata=true;                  資料傾斜引數,設定為true的話,會將一個MR作業切分成兩個,第一個MR作業中,map的結果會隨機分發到reduce中,這樣相同的key可能分發到不同的 reduce中,在reduce中做一些聚合操作,從而達到負載均衡的目的。第二個MR再按照正常的邏輯進行。  注意:這個引數不支援同時進行多列的count(distinct )操作。  會報如下錯誤:DISTINCT on different columns not supported with skew in data, 例如: select  count(distinct a.dvc_id ),count(distinct a.user_id)  from tds_did_user_targ_mon a join maptable b on a.dvc_id=b.dvc_id join maptable1 c on b.dvc_id=c.dvc_id; hive.exec.reducer.bytes.per.reduce=1000000000; hive.merge.mapredfiles=true; hive.merge.sparkfiles=true;