Skip to content

Commit cc51607

Browse files
committed
YARN-9085. Add Guaranteed and MaxCapacity to CSQueueMetrics
1 parent 6c852f2 commit cc51607

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CSQueueMetrics.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.hadoop.metrics2.annotation.Metrics;
2525
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
2626
import org.apache.hadoop.metrics2.lib.MutableGaugeFloat;
27+
import org.apache.hadoop.metrics2.lib.MutableGaugeInt;
2728
import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
2829
import org.apache.hadoop.yarn.api.records.Resource;
2930
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
@@ -46,6 +47,14 @@ public class CSQueueMetrics extends QueueMetrics {
4647
MutableGaugeFloat usedCapacity;
4748
@Metric("Percent of Absolute Capacity Used")
4849
MutableGaugeFloat absoluteUsedCapacity;
50+
@Metric("Guaranteed memory in MB")
51+
MutableGaugeLong guaranteedMB;
52+
@Metric("Guaranteed CPU in virtual cores")
53+
MutableGaugeInt guaranteedVCores;
54+
@Metric("Maximum memory in MB")
55+
MutableGaugeLong maxCapacityMB;
56+
@Metric("Maximum CPU in virtual cores")
57+
MutableGaugeInt maxCapacityVCores;
4958

5059
CSQueueMetrics(MetricsSystem ms, String queueName, Queue parent,
5160
boolean enableUserMetrics, Configuration conf) {
@@ -126,6 +135,36 @@ public void setAbsoluteUsedCapacity(String partition,
126135
}
127136
}
128137

138+
public long getGuaranteedMB() {
139+
return guaranteedMB.value();
140+
}
141+
142+
public int getGuaranteedVCores() {
143+
return guaranteedVCores.value();
144+
}
145+
146+
public void setGuaranteedResources(String partition, Resource res) {
147+
if (partition == null || partition.equals(RMNodeLabelsManager.NO_LABEL)) {
148+
guaranteedMB.set(res.getMemorySize());
149+
guaranteedVCores.set(res.getVirtualCores());
150+
}
151+
}
152+
153+
public long getMaxCapacityMB() {
154+
return maxCapacityMB.value();
155+
}
156+
157+
public int getMaxCapacityVCores() {
158+
return maxCapacityVCores.value();
159+
}
160+
161+
public void setMaxCapacityResources(String partition, Resource res) {
162+
if (partition == null || partition.equals(RMNodeLabelsManager.NO_LABEL)) {
163+
maxCapacityMB.set(res.getMemorySize());
164+
maxCapacityVCores.set(res.getVirtualCores());
165+
}
166+
}
167+
129168
public synchronized static CSQueueMetrics forQueue(String queueName,
130169
Queue parent, boolean enableUserMetrics, Configuration conf) {
131170
MetricsSystem ms = DefaultMetricsSystem.instance();

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,21 @@ public static void updateQueueStatistics(
314314
childQueue.getMetrics().setAvailableResourcesToQueue(nodePartition,
315315
getMaxAvailableResourceToQueue(rc, nlm, childQueue, cluster));
316316
}
317+
318+
/**
319+
* Updated configured capacity/max-capacity for queue.
320+
* @param rc resource calculator
321+
* @param partitionResource total cluster resources for this partition
322+
* @param partition partition being updated
323+
* @param queue queue
324+
*/
325+
public static void updateConfiguredCapacityMetrics(ResourceCalculator rc,
326+
Resource partitionResource, String partition, AbstractCSQueue queue) {
327+
queue.getMetrics().setGuaranteedResources(partition, rc.multiplyAndNormalizeDown(
328+
partitionResource, queue.getQueueCapacities().getAbsoluteCapacity(partition),
329+
queue.getMinimumAllocation()));
330+
queue.getMetrics().setMaxCapacityResources(partition, rc.multiplyAndNormalizeDown(
331+
partitionResource, queue.getQueueCapacities().getAbsoluteMaximumCapacity(partition),
332+
queue.getMinimumAllocation()));
333+
}
317334
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/LeafQueue.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,10 @@ public void updateClusterResource(Resource clusterResource,
18231823
// Update metrics
18241824
CSQueueUtils.updateQueueStatistics(resourceCalculator, clusterResource,
18251825
this, labelManager, null);
1826+
// Update configured capacity/max-capacity for default partition only
1827+
CSQueueUtils.updateConfiguredCapacityMetrics(resourceCalculator,
1828+
labelManager.getResourceByLabel(null, clusterResource),
1829+
RMNodeLabelsManager.NO_LABEL, this);
18261830

18271831
// queue metrics are updated, more resource may be available
18281832
// activate the pending applications if possible

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,10 @@ public void updateClusterResource(Resource clusterResource,
911911

912912
CSQueueUtils.updateQueueStatistics(resourceCalculator, clusterResource,
913913
this, labelManager, null);
914+
// Update configured capacity/max-capacity for default partition only
915+
CSQueueUtils.updateConfiguredCapacityMetrics(resourceCalculator,
916+
labelManager.getResourceByLabel(null, clusterResource),
917+
RMNodeLabelsManager.NO_LABEL, this);
914918
} finally {
915919
writeLock.unlock();
916920
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5128,4 +5128,48 @@ public void testMoveAppWithActiveUsersWithOnlyPendingApps() throws Exception {
51285128
assertEquals(4, appsInB1.size());
51295129
rm.close();
51305130
}
5131+
5132+
@Test
5133+
public void testCSQueueMetrics() throws Exception {
5134+
CapacityScheduler cs = new CapacityScheduler();
5135+
cs.setConf(new YarnConfiguration());
5136+
cs.setRMContext(resourceManager.getRMContext());
5137+
CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
5138+
setupQueueConfiguration(conf);
5139+
cs.init(conf);
5140+
cs.start();
5141+
5142+
RMNode n1 = MockNodes.newNodeInfo(0, MockNodes.newResource(50 * GB), 1, "n1");
5143+
RMNode n2 = MockNodes.newNodeInfo(0, MockNodes.newResource(50 * GB), 2, "n2");
5144+
cs.handle(new NodeAddedSchedulerEvent(n1));
5145+
cs.handle(new NodeAddedSchedulerEvent(n2));
5146+
5147+
assertEquals(10240, ((CSQueueMetrics)cs.getQueue("a").getMetrics()).getGuaranteedMB());
5148+
assertEquals(71680, ((CSQueueMetrics)cs.getQueue("b1").getMetrics()).getGuaranteedMB());
5149+
assertEquals(102400, ((CSQueueMetrics)cs.getQueue("a").getMetrics()).getMaxCapacityMB());
5150+
assertEquals(102400, ((CSQueueMetrics)cs.getQueue("b1").getMetrics()).getMaxCapacityMB());
5151+
5152+
// Remove a node, metrics should be updated
5153+
cs.handle(new NodeRemovedSchedulerEvent(n2));
5154+
assertEquals(5120, ((CSQueueMetrics)cs.getQueue("a").getMetrics()).getGuaranteedMB());
5155+
assertEquals(35840, ((CSQueueMetrics)cs.getQueue("b1").getMetrics()).getGuaranteedMB());
5156+
assertEquals(51200, ((CSQueueMetrics)cs.getQueue("a").getMetrics()).getMaxCapacityMB());
5157+
assertEquals(51200, ((CSQueueMetrics)cs.getQueue("b1").getMetrics()).getMaxCapacityMB());
5158+
5159+
// Add child queue to a, and reinitialize. Metrics should be updated
5160+
conf.setQueues(CapacitySchedulerConfiguration.ROOT + ".a", new String[] {"a1", "a2", "a3"} );
5161+
conf.setCapacity(CapacitySchedulerConfiguration.ROOT + ".a.a2", 30.0f);
5162+
conf.setCapacity(CapacitySchedulerConfiguration.ROOT + ".a.a3", 40.0f);
5163+
conf.setMaximumCapacity(CapacitySchedulerConfiguration.ROOT + ".a.a3", 50.0f);
5164+
5165+
cs.reinitialize(conf, new RMContextImpl(null, null, null, null, null,
5166+
null, new RMContainerTokenSecretManager(conf),
5167+
new NMTokenSecretManagerInRM(conf),
5168+
new ClientToAMTokenSecretManagerInRM(), null));
5169+
5170+
assertEquals(1024, ((CSQueueMetrics)cs.getQueue("a2").getMetrics()).getGuaranteedMB());
5171+
assertEquals(2048, ((CSQueueMetrics)cs.getQueue("a3").getMetrics()).getGuaranteedMB());
5172+
assertEquals(51200, ((CSQueueMetrics)cs.getQueue("a2").getMetrics()).getMaxCapacityMB());
5173+
assertEquals(25600, ((CSQueueMetrics)cs.getQueue("a3").getMetrics()).getMaxCapacityMB());
5174+
}
51315175
}

0 commit comments

Comments
 (0)