本文主要是介绍FairScheduler源码资源抢占,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
FairScheduler类
private class UpdateThread extends Thread {@Overridepublic void run() {while (!Thread.currentThread().isInterrupted()) {try {Thread.sleep(updateInterval); //默认500mslong start = getClock().getTime();update();preemptTasksIfNecessary(); /抢占long duration = getClock().getTime() - start;fsOpDurations.addUpdateThreadRunDuration(duration);} catch (InterruptedException ie) {LOG.warn("Update thread interrupted. Exiting.");return;} catch (Exception e) {LOG.error("Exception in fair scheduler UpdateThread", e);}}}}protected synchronized void preemptTasksIfNecessary() {if (!shouldAttemptPreemption()) { 判断是否应该尝试抢占return;}long curTime = getClock().getTime();if (curTime - lastPreemptCheckTime < preemptionInterval) { ///抢占间隔 ,默认值5000msreturn;}lastPreemptCheckTime = curTime;Resource resToPreempt = Resources.clone(Resources.none());for (FSLeafQueue sched : queueMgr.getLeafQueues()) {Resources.addTo(resToPreempt, resToPreempt(sched, curTime));//resToPreempt方法是关键,返回队列该抢占的量,为两个Resource对象,内存和cpu相加到resToPreempt,resToPreempt方法返回队列允许的被抢占资源的多少}if (Resources.greaterThan(RESOURCE_CALCULATOR, clusterResource, resToPreempt,Resources.none())) { 最后调用的是DefaultResourceCalculator里的compare方法,用resToPreempt内存减Resources.none内存preemptResources(resToPreempt); //抢占资源方法}}private boolean shouldAttemptPreemption() {if (preemptionEnabled) {return (preemptionUtilizationThreshold < Math.max(
这篇关于FairScheduler源码资源抢占的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!