From b9c5c5de6813af21e999ab75d37761c9eb57e91b Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Fri, 29 May 2015 15:17:02 -0700 Subject: [PATCH] YARN-3547. FairScheduler: Apps that have no resource demand should not participate scheduling. (Xianyin Xin via kasha) (cherry picked from commit 3ae2a625018bc8cf431aa19da5bf8fe4ef8c1ad4) --- hadoop-yarn-project/CHANGES.txt | 3 ++ .../scheduler/fair/FSLeafQueue.java | 43 +++++++++---------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 6800095f299..31590f8a05f 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -243,6 +243,9 @@ Release 2.8.0 - UNRELEASED YARN-3006. Improve the error message when attempting manual failover with auto-failover enabled. (Akira AJISAKA via wangda) + YARN-3547. FairScheduler: Apps that have no resource demand should not participate + scheduling. (Xianyin Xin via kasha) + BUG FIXES YARN-3197. Confusing log generated by CapacityScheduler. (Varun Saxena diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSLeafQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSLeafQueue.java index 04dbd2f57ff..6779a1b3777 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSLeafQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSLeafQueue.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.TreeSet; import com.google.common.annotations.VisibleForTesting; import org.apache.commons.logging.Log; @@ -314,35 +315,33 @@ public class FSLeafQueue extends FSQueue { return assigned; } - Comparator comparator = policy.getComparator(); - writeLock.lock(); - try { - Collections.sort(runnableApps, comparator); - } finally { - writeLock.unlock(); - } - // Release write lock here for better performance and avoiding deadlocks. - // runnableApps can be in unsorted state because of this section, - // but we can accept it in practice since the probability is low. + // Apps that have resource demands. + TreeSet pendingForResourceApps = + new TreeSet(policy.getComparator()); readLock.lock(); try { - for (FSAppAttempt sched : runnableApps) { - if (SchedulerAppUtils.isBlacklisted(sched, node, LOG)) { - continue; - } - - assigned = sched.assignContainer(node); - if (!assigned.equals(Resources.none())) { - if (LOG.isDebugEnabled()) { - LOG.debug("Assigned container in queue:" + getName() + " " + - "container:" + assigned); - } - break; + for (FSAppAttempt app : runnableApps) { + Resource pending = app.getAppAttemptResourceUsage().getPending(); + if (!pending.equals(Resources.none())) { + pendingForResourceApps.add(app); } } } finally { readLock.unlock(); } + for (FSAppAttempt sched : pendingForResourceApps) { + if (SchedulerAppUtils.isBlacklisted(sched, node, LOG)) { + continue; + } + assigned = sched.assignContainer(node); + if (!assigned.equals(Resources.none())) { + if (LOG.isDebugEnabled()) { + LOG.debug("Assigned container in queue:" + getName() + " " + + "container:" + assigned); + } + break; + } + } return assigned; }