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/FSAppAttempt.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/FSAppAttempt.java index bbd4418873..94991ebb14 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/FSAppAttempt.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/FSAppAttempt.java @@ -1304,7 +1304,20 @@ public Resource getResourceUsage() { @Override public float getWeight() { - return scheduler.getAppWeight(this); + double weight = 1.0; + + if (scheduler.isSizeBasedWeight()) { + scheduler.getSchedulerReadLock().lock(); + + try { + // Set weight based on current memory demand + weight = Math.log1p(getDemand().getMemorySize()) / Math.log(2); + } finally { + scheduler.getSchedulerReadLock().unlock(); + } + } + + return (float)weight * this.getPriority().getPriority(); } @Override 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/FairScheduler.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/FairScheduler.java index 7f1b91e32a..b2978d4ce3 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/FairScheduler.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/FairScheduler.java @@ -368,21 +368,8 @@ public void update() { return rmContext.getContainerTokenSecretManager(); } - public float getAppWeight(FSAppAttempt app) { - double weight = 1.0; - - if (sizeBasedWeight) { - readLock.lock(); - - try { - // Set weight based on current memory demand - weight = Math.log1p(app.getDemand().getMemorySize()) / Math.log(2); - } finally { - readLock.unlock(); - } - } - - return (float)weight * app.getPriority().getPriority(); + public boolean isSizeBasedWeight() { + return sizeBasedWeight; } public Resource getIncrementResourceCapability() {