From ab93bf5b00fa090d7a78ccc13f0d1529439f0b83 Mon Sep 17 00:00:00 2001 From: Daniel Templeton Date: Sat, 28 Oct 2017 09:13:13 -0700 Subject: [PATCH] YARN-7397. Reduce lock contention in FairScheduler#getAppWeight() (cherry picked from commit e62bbbca7adafa0e050212e99c41c95a844700ff) --- .../scheduler/fair/FairScheduler.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 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/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 04418598bf8..8ea07ab8b1e 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 @@ -369,17 +369,20 @@ public class FairScheduler extends } public float getAppWeight(FSAppAttempt app) { - try { + double weight = 1.0; + + if (sizeBasedWeight) { readLock.lock(); - double weight = 1.0; - if (sizeBasedWeight) { + + 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(); - } finally { - readLock.unlock(); } + + return (float)weight * app.getPriority().getPriority(); } public Resource getIncrementResourceCapability() {