From 8db9d61ac2e04888cb228b29fe54b41c730cf0e6 Mon Sep 17 00:00:00 2001 From: Daniel Templeton Date: Tue, 7 Nov 2017 14:53:48 -0800 Subject: [PATCH] YARN-7401. Reduce lock contention in ClusterNodeTracker#getClusterCapacity() --- .../scheduler/ClusterNodeTracker.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 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/ClusterNodeTracker.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/ClusterNodeTracker.java index ccec6bc6a8..60ef390a3b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/ClusterNodeTracker.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/ClusterNodeTracker.java @@ -55,8 +55,9 @@ public class ClusterNodeTracker { private Map nodeNameToNodeMap = new HashMap<>(); private Map> nodesPerRack = new HashMap<>(); - private Resource clusterCapacity = Resources.clone(Resources.none()); - private Resource staleClusterCapacity = null; + private final Resource clusterCapacity = Resources.clone(Resources.none()); + private volatile Resource staleClusterCapacity = + Resources.clone(Resources.none()); // Max allocation private long maxNodeMemory = -1; @@ -82,6 +83,7 @@ public void addNode(N node) { // Update cluster capacity Resources.addTo(clusterCapacity, node.getTotalResource()); + staleClusterCapacity = Resources.clone(clusterCapacity); // Update maximumAllocation updateMaxResources(node, true); @@ -139,16 +141,7 @@ public int nodeCount(String rackName) { } public Resource getClusterCapacity() { - readLock.lock(); - try { - if (staleClusterCapacity == null || - !Resources.equals(staleClusterCapacity, clusterCapacity)) { - staleClusterCapacity = Resources.clone(clusterCapacity); - } - return staleClusterCapacity; - } finally { - readLock.unlock(); - } + return staleClusterCapacity; } public N removeNode(NodeId nodeId) { @@ -175,6 +168,7 @@ public N removeNode(NodeId nodeId) { // Update cluster capacity Resources.subtractFrom(clusterCapacity, node.getTotalResource()); + staleClusterCapacity = Resources.clone(clusterCapacity); // Update maximumAllocation updateMaxResources(node, false);