From 81c3a3c8428a2736875a779b11b77d920248edf3 Mon Sep 17 00:00:00 2001 From: Sunil G Date: Wed, 22 Nov 2017 23:07:01 +0530 Subject: [PATCH] YARN-7538-YARN-5881 --- .../scheduler/AbstractResourceUsage.java | 53 ++++++++++++++-------- .../scheduler/capacity/AbstractCSQueue.java | 4 +- .../scheduler/capacity/CSQueueUtils.java | 8 ++-- .../scheduler/capacity/ParentQueue.java | 4 +- 4 files changed, 43 insertions(+), 26 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/AbstractResourceUsage.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractResourceUsage.java index c2953236f47..cf30f6b80eb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractResourceUsage.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractResourceUsage.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; @@ -39,6 +40,7 @@ protected ReadLock readLock; protected WriteLock writeLock; protected Map usages; + UsageByLabel noLabelUsages; // short for no-label :) private static final String NL = CommonNodeLabelsManager.NO_LABEL; @@ -49,6 +51,7 @@ public AbstractResourceUsage() { usages = new HashMap(); usages.put(NL, new UsageByLabel(NL)); + noLabelUsages = new UsageByLabel(NL); } // Usage enum here to make implement cleaner @@ -69,29 +72,29 @@ private ResourceType(int value) { public static class UsageByLabel { // usage by label, contains all UsageType - private Resource[] resArr; + private AtomicReferenceArray resArr; public UsageByLabel(String label) { - resArr = new Resource[ResourceType.values().length]; - for (int i = 0; i < resArr.length; i++) { - resArr[i] = Resource.newInstance(0, 0); - }; + resArr = new AtomicReferenceArray(ResourceType.values().length); + for (int i = 0; i < resArr.length(); i++) { + resArr.set(i, Resource.newInstance(0, 0)); + } ; } public Resource getUsed() { - return resArr[ResourceType.USED.idx]; + return resArr.get(ResourceType.USED.idx); } @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("{used=" + resArr[0] + "%, "); - sb.append("pending=" + resArr[1] + "%, "); - sb.append("am_used=" + resArr[2] + "%, "); - sb.append("reserved=" + resArr[3] + "%}"); - sb.append("min_eff=" + resArr[9] + "%, "); - sb.append("max_eff=" + resArr[10] + "%}"); - sb.append("min_effup=" + resArr[11] + "%, "); + sb.append("{used=" + resArr.get(0) + "%, "); + sb.append("pending=" + resArr.get(1) + "%, "); + sb.append("am_used=" + resArr.get(2) + "%, "); + sb.append("reserved=" + resArr.get(3) + "%}"); + sb.append("min_eff=" + resArr.get(9) + "%, "); + sb.append("max_eff=" + resArr.get(10) + "%}"); + sb.append("min_effup=" + resArr.get(11) + "%, "); return sb.toString(); } } @@ -108,13 +111,17 @@ protected Resource _get(String label, ResourceType type) { label = RMNodeLabelsManager.NO_LABEL; } + if (label.equals(RMNodeLabelsManager.NO_LABEL)) { + return normalize(noLabelUsages.resArr.get(type.idx)); + } + try { readLock.lock(); UsageByLabel usage = usages.get(label); if (null == usage) { return Resources.none(); } - return normalize(usage.resArr[type.idx]); + return normalize(usage.resArr.get(type.idx)); } finally { readLock.unlock(); } @@ -126,7 +133,7 @@ protected Resource _getAll(ResourceType type) { Resource allOfType = Resources.createResource(0); for (Map.Entry usageEntry : usages.entrySet()) { //all usages types are initialized - Resources.addTo(allOfType, usageEntry.getValue().resArr[type.idx]); + Resources.addTo(allOfType, usageEntry.getValue().resArr.get(type.idx)); } return allOfType; } finally { @@ -138,6 +145,11 @@ private UsageByLabel getAndAddIfMissing(String label) { if (label == null) { label = RMNodeLabelsManager.NO_LABEL; } + + if (label.equals(RMNodeLabelsManager.NO_LABEL)) { + return noLabelUsages; + } + if (!usages.containsKey(label)) { UsageByLabel u = new UsageByLabel(label); usages.put(label, u); @@ -148,10 +160,15 @@ private UsageByLabel getAndAddIfMissing(String label) { } protected void _set(String label, ResourceType type, Resource res) { + if (label.equals(RMNodeLabelsManager.NO_LABEL)) { + noLabelUsages.resArr.set(type.idx, res); + return; + } + try { writeLock.lock(); UsageByLabel usage = getAndAddIfMissing(label); - usage.resArr[type.idx] = res; + usage.resArr.set(type.idx, res); } finally { writeLock.unlock(); } @@ -161,7 +178,7 @@ protected void _inc(String label, ResourceType type, Resource res) { try { writeLock.lock(); UsageByLabel usage = getAndAddIfMissing(label); - Resources.addTo(usage.resArr[type.idx], res); + Resources.addTo(usage.resArr.get(type.idx), res); } finally { writeLock.unlock(); } @@ -171,7 +188,7 @@ protected void _dec(String label, ResourceType type, Resource res) { try { writeLock.lock(); UsageByLabel usage = getAndAddIfMissing(label); - Resources.subtractFrom(usage.resArr[type.idx], res); + Resources.subtractFrom(usage.resArr.get(type.idx), res); } finally { writeLock.unlock(); } 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/capacity/AbstractCSQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/AbstractCSQueue.java index 9caf5891000..140ea5dc903 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/AbstractCSQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/AbstractCSQueue.java @@ -932,7 +932,7 @@ public void incUsedResource(String nodeLabel, Resource resourceToInc, queueUsage.incUsed(nodeLabel, resourceToInc); CSQueueUtils.updateUsedCapacity(resourceCalculator, labelManager.getResourceByLabel(nodeLabel, Resources.none()), - Resources.none(), nodeLabel, this); + nodeLabel, this); if (null != parent) { parent.incUsedResource(nodeLabel, resourceToInc, null); } @@ -948,7 +948,7 @@ public void decUsedResource(String nodeLabel, Resource resourceToDec, queueUsage.decUsed(nodeLabel, resourceToDec); CSQueueUtils.updateUsedCapacity(resourceCalculator, labelManager.getResourceByLabel(nodeLabel, Resources.none()), - Resources.none(), nodeLabel, this); + nodeLabel, this); if (null != parent) { parent.decUsedResource(nodeLabel, resourceToDec, null); } 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/capacity/CSQueueUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CSQueueUtils.java index 81dec80d0eb..6daca5158a3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CSQueueUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CSQueueUtils.java @@ -180,8 +180,8 @@ private static void updateAbsoluteCapacitiesByNodeLabels( * used resource for all partitions of this queue. */ public static void updateUsedCapacity(final ResourceCalculator rc, - final Resource totalPartitionResource, Resource clusterResource, - String nodePartition, AbstractCSQueue childQueue) { + final Resource totalPartitionResource, String nodePartition, + AbstractCSQueue childQueue) { QueueCapacities queueCapacities = childQueue.getQueueCapacities(); CSQueueMetrics queueMetrics = childQueue.getMetrics(); ResourceUsage queueResourceUsage = childQueue.getQueueResourceUsage(); @@ -287,11 +287,11 @@ public static void updateQueueStatistics( for (String partition : Sets.union(queueCapacities.getNodePartitionsSet(), queueResourceUsage.getNodePartitionsSet())) { updateUsedCapacity(rc, nlm.getResourceByLabel(partition, cluster), - cluster, partition, childQueue); + partition, childQueue); } } else { updateUsedCapacity(rc, nlm.getResourceByLabel(nodePartition, cluster), - cluster, nodePartition, childQueue); + nodePartition, childQueue); } // Update queue metrics w.r.t node labels. In a generic way, we can 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/capacity/ParentQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/ParentQueue.java index a427fb135ab..c198d135ed2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/ParentQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/ParentQueue.java @@ -739,8 +739,8 @@ private ResourceLimits getResourceLimitsOfChild(CSQueue child, child.getQueueResourceUsage().getUsed(nodePartition)); // Get child's max resource - Resource childConfiguredMaxResource = getEffectiveMaxCapacityDown( - nodePartition, minimumAllocation); + Resource childConfiguredMaxResource = child + .getEffectiveMaxCapacityDown(nodePartition, minimumAllocation); // Child's limit should be capped by child configured max resource childLimit = -- 2.13.6 (Apple Git-96)