1. 程式人生 > >mapreduce uber模式

mapreduce uber模式

什麼是uber模式

Uber模式簡單地可以理解成JVM重用,該模式是2.x開始引入的;以Uber模式執行MR作業,所有的Map Tasks和Reduce Tasks將會在ApplicationMaster所在的容器(container)中執行,也就是說整個MR作業執行的過程只會啟動AM container,因為不需要啟動mapper 和 reducer containers,所以AM不需要和遠端containers通訊,整個過程簡單了。

不是所有的MR作業都可以啟用Uber模式,如果我們的MR作業輸入的資料量非常小,啟動Map container或Reduce container的時間都比處理資料要長,那麼這個作業就可以考慮啟用Uber模式執行,一般情況下,對小作業啟用Uber模式執行會得到2x-3x的效能提升。

啟用uber模式的要求非常嚴格,程式碼如下:

isUber = uberEnabled && smallNumMapTasks && smallNumReduceTasks && smallInput && smallMemory && smallCpu && notChainJob && isValidUberMaxReduces;

  • uberEnabled:其實就是 mapreduce.job.ubertask.enable 引數的值,預設情況下為 false ;也就是說預設情況不啟用Uber模式;

  • smallNumMapTasks:啟用Uber模式的作業Map的個數必須小於等於 mapreduce.job.ubertask.maxmaps 引數的值,該值預設為9;也計算說,在預設情況下,如果你想啟用Uber模式,作業的Map個數必須小於10;

  • smallNumReduceTasks:同理,Uber模式的作業Reduce的個數必須小於等於mapreduce.job.ubertask.maxreduces,該值預設為1;也計算說,在預設情況下,如果你想啟用Uber模式,作業的Reduce個數必須小於等於1;

  • smallInput:不是任何作業都適合啟用Uber模式的,輸入資料的大小必須小於等於 mapreduce.job.ubertask.maxbytes 引數的值,預設情況是HDFS一個檔案塊大小;

  • smallMemory:因為作業是在AM所在的container中執行,所以要求我們設定的Map記憶體(mapreduce.map.memory.mb)和Reduce記憶體(mapreduce.reduce.memory.mb)必須小於等於 AM所在容器記憶體大小設定(yarn.app.mapreduce.am.resource.mb);

  • smallCpu:同理,Map配置的vcores(mapreduce.map.cpu.vcores)個數和 Reduce配置的vcores(mapreduce.reduce.cpu.vcores)個數也必須小於等於AM所在容器vcores個數的設定(yarn.app.mapreduce.am.resource.cpu-vcores);

  • notChainJob:此外,處理資料的Map class(mapreduce.job.map.class)和Reduce class(mapreduce.job.reduce.class)必須不是 ChainMapper 或 ChainReducer 才行;

  • isValidUberMaxReduces:目前僅當Reduce的個數小於等於1的作業才能啟用Uber模式。

同時滿足上面八個條件才能在作業執行的時候啟動Uber模式。下面是一個啟用Uber模式執行的作業執行成功的日誌:

File System Counters FILE: Number of bytes read=215 FILE: Number of bytes written=505 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=1200 HDFS: Number of bytes written=274907 HDFS: Number of read operations=57 HDFS: Number of large read operations=0 HDFS: Number of write operations=11 Job Counters Launched map tasks=2 Launched reduce tasks=1 Other local map tasks=2 Total time spent by all maps in occupied slots (ms)=3664 Total time spent by all reduces in occupied slots (ms)=2492 TOTAL_LAUNCHED_UBERTASKS=3 NUM_UBER_SUBMAPS=2 NUM_UBER_SUBREDUCES=1 Map-Reduce Framework Map input records=2 Map output records=8 Map output bytes=82 Map output materialized bytes=85 Input split bytes=202 Combine input records=8 Combine output records=6 Reduce input groups=5 Reduce shuffle bytes=0 Reduce input records=6 Reduce output records=5 Spilled Records=12 Shuffled Maps =0 Failed Shuffles=0 Merged Map outputs=0 GC time elapsed (ms)=65 CPU time spent (ms)=1610 Physical memory (bytes) snapshot=1229729792 Virtual memory (bytes) snapshot=5839392768 Total committed heap usage (bytes)=3087532032 File Input Format Counters Bytes Read=50 File Output Format Counters Bytes Written=41

細心的同學應該會發現裡面多了 TOTAL_LAUNCHED_UBERTASKS、NUM_UBER_SUBMAPS 以及 NUM_UBER_SUBREDUCES 資訊,以前需要啟用Map Task 或 Reduce Task執行的工作直接在AM中執行,所有出現了NUM_UBER_SUBMAPS和原來Map Task個數一樣;同理,NUM_UBER_SUBREDUCES 和Reduce Task個數一樣。