Opportunistic Containers代碼追蹤

本文基於Hadoop 3.0.0

Yarn容器分爲2種:

Guaranteed Containers:
節點上存在未分配的資源時纔將容器分配給節點
Opportunistic Containers:
在調度時沒有可用的資源也可以將容器分派給NM。在這種情況下,Opportunistic容器將在NM處排隊,等待資源可用。

如果有可用資源,則無論其執行類型如何,都會立即啓動容器的執行。
如果沒有可用資源:
Guaranteed Containers:根據要執行的Guaranteed容器的要求殺死Opportunistic容器,然後開始執行。
Opportunistic Containers:保留在隊列中,直到資源可用。
當一個容器完成其執行並釋放資源時,我們檢查排隊的容器,如果有可用的資源,就開始執行它們。默認以FIFO順序從隊列中選擇容器。

默認不開啓Opportunistic Container,如果需要使用該功能需要在yarn-site.xml文件中配置如下Property:

配置及測試見官網:http://hadoop.apache.org/docs/r3.0.0/hadoop-yarn/hadoop-yarn-site/OpportunisticContainers.html

 測試用例爲 pi

$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.0.3.jar pi -Dmapreduce.job.num-opportunistic-maps-percent="40" 10 100

參數含義:

每100個Container中Opportunistic Containers的數量爲40

Number of Maps = 10
Samples per Map = 100

pi程序的程序入口:QuasiMonteCarlo.java

首先進行參數處理,將num-opportunistic-maps-percent值設爲輸入值(默認爲0)

之後提交job,啓動AM:MRAppMaster.java

AM生成相應的ContainerRequest,mapsMod100的意思是現在已經申請的map containers數量 mod 100,numOpportunisticMapsPercent就是我們之前輸入的參數。

RM通過AMserver接受AM的Request,當開啓Opportunistic選項時,RM開啓oppContainerAllocatingAMService,否則開啓正常的ApplicationMasterService。

oppContainerAllocatingAMService將opportunities request和guaranteed request分開處理

 

 

 

 NM對於opportunities container和guaranteed container的調度

 首先若請求是開啓GuarnateedContainer時,入隊,直接啓動。(在資源足夠時直接啓動,否則殺死一些Opportunistic containers以獲取足夠的資源)

如果是Opportunistic containers,則先啓動隊列中的Guaranteed containers,之後再啓動自身。