Capacity Scheduler(基于hadoop 2.7.6)
Capacity Scheduler 主要功能:
1.应用程序初始化
应用程序提交到ResourceManager后,ResouceManager会向Capacity Scheduler发送一个SchedulerEventType.APP_ADDED事件,Capacity Scheduler收到该事件后,将为应用程序创建一个SchedulerApplication(主要包括queue,user,FiCaSchedulerApp成员)对象跟踪和维护该应用程序的运行时信息,同时将应用程序提交到对应的叶子队列,叶子队列会对应用程序进行一系列合法性检查.
2.资源调度
当ResourceManager收到来自NodeManager发送的心跳信息后,将向Capacity Scheduler发送一个SchedulerEventType.NODE_UPDATE事件,Capacity Scheduler收到该事件后,会依次进行一下操作:
(1)处理心跳信息
(2)资源分配
APP_ATTEMPT_ADDED事件主要处理逻辑:
1.创建FiCaSchedulerApp类型的application,通过队列资源上限和用户资源上限检查后,记录到队列的activeApplications等待资源调度分配(即收到数据节点的NODE_UPDATE事件时进行资源调度分配).
2.触发RMAppAttemptEventType.ATTEMPT_ADDED事件,该事件由ScheduleTransition转换器处理.
下面贴贴SchedulerEventType.APP_ATTEMPT_ADDED的处理代码清单:
@Override
public void CapacityScheduler.handle(SchedulerEvent event) {
...省略...
/**
* 1.利用user的pendingApplications和activateApplications两个域计数用户启动的应用程序数量
* 2.利用队列的pengdingApplications和activateApplications两个域,切换计算是否符合资源上限:
* 符合则加入队列的activateApplications列表等待资源调度分配
*/
case APP_ATTEMPT_ADDED:
{
AppAttemptAddedSchedulerEvent appAttemptAddedEvent =
(AppAttemptAddedSchedulerEvent) event;
addApplicationAttempt(appAttemptAddedEvent.getApplicationAttemptId(),
appAttemptAddedEvent.getTransferStateFromPreviousAttempt(),
appAttemptAddedEvent.getIsAttemptRecovering());
}
break;
...省略...
}
private synchronized void addApplicationAttempt(
ApplicationAttemptId applicationAttemptId,
boolean transferStateFromPreviousAttempt,
boolean isAttemptRecovering) {
/**
* 在处理SchedulerEventType.APP_ADDED事件时,已经实例化了SchedulerApplication对象
* FiCaSchedulerApp类我的理解: 它是在Application Attempt在Scheduler端的实现
*/
SchedulerApplication<FiCaSchedulerApp> application =
applications.get(applicationAttemptId.getApplicationId());
if (application == null) {
LOG.warn("Application " + applicationAttemptId.getApplicationId() +
" cannot be found in scheduler.");
return;
}
CSQueue queue = (CSQueue) application.getQueue();
/**
* 创建FiCaSchedulerApp用于记录AppAttempt运行信息
* FiCaSchedulerApp继承自SchedulerApplicationAttempt
* 主要主体分配逻辑相关的主要成员是
* 1.appSchedulingInfo:AppSchedulingInfo
* 2.attemptId:ApplicationAttemptId
* 3.liveContainers:Map<ContainerId, RMContainer>
* appSchedulingInfo里有一个Map<Priority, Map<String, ResourceRequest>>类型的需求列表,后面进行资源分配时根据其具体值进行判断是否可以分配.
*/
FiCaSchedulerApp attempt =
new FiCaSchedulerApp(applicationAttemptId, application.getUser