Hive merge(小檔案合并),

來源:互聯網
上載者:User

Hive merge(小檔案合并),

當Hive的輸入由很多個小檔案組成時,如果不涉及檔案合并的話,那麼每個小檔案都會啟動一個map task。
如果檔案過小,以至於map任務啟動和初始化的時間大於邏輯處理的時間,會造成資源浪費,甚至發生OutOfMemoryError錯誤。
因此,當我們啟動一個任務時,如果發現輸入資料量小但任務數量多時,需要注意在Map前端進行輸入小檔案合併作業。
同理,向一個表寫資料時,注意觀察reduce數量,注意輸出檔案大小。


1、 Map輸入小檔案合并
#每個Map處理的最大輸入檔案大小(256MB)
set mapred.max.split.size=256000000;  
#一個節點上split檔案的最小值
set mapred.min.split.size.per.node=100000000; 
#一個交換器下split檔案的最小值
set mapred.min.split.size.per.rack=100000000; 
#執行Map前進行小檔案合并
set hive.input.format=org.apache.hadoop.hive.ql.io.CombineHiveInputFormat;  

在開啟了org.apache.hadoop.hive.ql.io.CombineHiveInputFormat 後,
一個data node節點上多個小檔案會進行合并,合并檔案數由mapred.max.split.size限制的大小決定。
mapred.min.split.size.per.node決定了多個data node上的檔案是否需要合并
mapred.min.split.size.per.rack決定了多個交換器上的檔案是否需要合并

2、輸出檔案合并
#在Map-Only的任務結束時就會合并小檔案
set hive.merge.mapfiles = true;
#在MapR-educe的任務結束時合并小檔案
set hive.merge.mapredfiles = true;(預設為false)
#合并檔案的大小
set hive.merge.size.per.task = 256*1000*1000;
#當輸出檔案的平均大小小於該值時,啟動一個獨立的map-reduce任務進行檔案merge
set hive.merge.smallfiles.avgsize=16000000 ;

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.