From b246c547490dd94271806ca4caf1e5f199f0fb09 Mon Sep 17 00:00:00 2001 From: Daniel Templeton Date: Wed, 15 Nov 2017 09:56:37 -0800 Subject: [PATCH] YARN-7414. FairScheduler#getAppWeight() should be moved into FSAppAttempt#getWeight() (Contributed by Soumabrata Chakraborty via Daniel Templeton) --- .../scheduler/fair/FSAppAttempt.java | 15 ++++++++++++++- .../scheduler/fair/FairScheduler.java | 17 ++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) 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() {