本文基于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,之后再启动自身。

 

posted on 2019-01-17 16:09  yxq1406  阅读(370)  评论(0编辑  收藏  举报