YARN-7401. Reduce lock contention in ClusterNodeTracker#getClusterCapacity()

This commit is contained in:
Daniel Templeton 2017-11-07 14:53:48 -08:00
parent 13fa2d4e3e
commit 8db9d61ac2

View File

@ -55,8 +55,9 @@ public class ClusterNodeTracker<N extends SchedulerNode> {
private Map<String, N> nodeNameToNodeMap = new HashMap<>();
private Map<String, List<N>> 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();
}
}
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);