YARN-7397. Reduce lock contention in FairScheduler#getAppWeight()

Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e62bbbca
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e62bbbca
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e62bbbca

Branch: refs/heads/YARN-1011
Commit: e62bbbca7adafa0e050212e99c41c95a844700ff
Parents: 9c5c687
Author: Daniel Templeton <templ...@apache.org>
Authored: Sat Oct 28 09:13:13 2017 -0700
Committer: Daniel Templeton <templ...@apache.org>
Committed: Sat Oct 28 09:13:13 2017 -0700

----------------------------------------------------------------------
 .../scheduler/fair/FairScheduler.java                | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/e62bbbca/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
----------------------------------------------------------------------
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 0441859..8ea07ab 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() {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to