Skip to content

Commit 6f2226a

Browse files
author
Eric E Payne
committed
YARN-9756: Create metric that sums total memory/vcores preempted per round. Contributed by Manikandan R (manirajv06).
1 parent 3e6a016 commit 6f2226a

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-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/QueueMetrics.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public class QueueMetrics implements MetricsSource {
7777
@Metric("# of active applications") MutableGaugeInt activeApplications;
7878
@Metric("App Attempt First Container Allocation Delay")
7979
MutableRate appAttemptFirstContainerAllocationDelay;
80+
@Metric("Aggregate total of preempted memory MB")
81+
MutableCounterLong aggregateMemoryMBPreempted;
82+
@Metric("Aggregate total of preempted vcores")
83+
MutableCounterLong aggregateVcoresPreempted;
8084

8185
//Metrics updated only for "default" partition
8286
@Metric("Allocated memory in MB") MutableGaugeLong allocatedMB;
@@ -586,6 +590,23 @@ public void updatePreemptedVcoreSeconds(long vcoreSeconds) {
586590
}
587591
}
588592

593+
public void updatePreemptedResources(Resource res) {
594+
aggregateMemoryMBPreempted.incr(res.getMemorySize());
595+
aggregateVcoresPreempted.incr(res.getVirtualCores());
596+
if (parent != null) {
597+
parent.updatePreemptedResources(res);
598+
}
599+
}
600+
601+
public void updatePreemptedForCustomResources(Resource res) {
602+
if (queueMetricsForCustomResources != null) {
603+
queueMetricsForCustomResources.increaseAggregatedPreempted(res);
604+
}
605+
if (parent != null) {
606+
parent.updatePreemptedForCustomResources(res);
607+
}
608+
}
609+
589610
public void updatePreemptedSecondsForCustomResources(Resource res,
590611
long seconds) {
591612
if (queueMetricsForCustomResources != null) {
@@ -753,6 +774,16 @@ public MutableCounterLong getAggregateVcoreSecondsPreempted() {
753774
return aggregateVcoreSecondsPreempted;
754775
}
755776

777+
@VisibleForTesting
778+
public long getAggregateMemoryMBPreempted() {
779+
return aggregateMemoryMBPreempted.value();
780+
}
781+
782+
@VisibleForTesting
783+
public long getAggregateVcoresPreempted() {
784+
return aggregateVcoresPreempted.value();
785+
}
786+
756787
public long getAllocatedMB() {
757788
return allocatedMB.value();
758789
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
public class QueueMetricsForCustomResources {
2929
private final QueueMetricsCustomResource aggregatePreemptedSeconds =
3030
new QueueMetricsCustomResource();
31+
private final QueueMetricsCustomResource aggregatePreempted =
32+
new QueueMetricsCustomResource();
3133
private final QueueMetricsCustomResource allocated =
3234
new QueueMetricsCustomResource();
3335
private final QueueMetricsCustomResource available =
@@ -82,6 +84,10 @@ public void increaseAggregatedPreemptedSeconds(Resource res, long seconds) {
8284
aggregatePreemptedSeconds.increaseWithMultiplier(res, seconds);
8385
}
8486

87+
public void increaseAggregatedPreempted(Resource res) {
88+
aggregatePreempted.increase(res);
89+
}
90+
8591
Map<String, Long> getAllocatedValues() {
8692
return allocated.getValues();
8793
}

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,9 @@ private void updateQueuePreemptionMetrics(RMContainer rmc) {
22222222
/ DateUtils.MILLIS_PER_SECOND;
22232223
metrics.updatePreemptedMemoryMBSeconds(mbSeconds);
22242224
metrics.updatePreemptedVcoreSeconds(vcSeconds);
2225+
metrics.updatePreemptedResources(containerResource);
22252226
metrics.updatePreemptedSecondsForCustomResources(containerResource,
22262227
usedSeconds);
2228+
metrics.updatePreemptedForCustomResources(containerResource);
22272229
}
22282230
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ protected RMNodeLabelsManager createNodeLabelManager() {
185185
Assert.assertEquals("Number of preempted containers incorrectly recorded:",
186186
4, cs.getQueue("root").getMetrics().getAggregatePreemptedContainers());
187187

188+
Assert.assertEquals("Amount of preempted memory incorrectly recorded:",
189+
4 * GB,
190+
cs.getQueue("root").getMetrics().getAggregateMemoryMBPreempted());
191+
192+
Assert.assertEquals("Number of preempted vcores incorrectly recorded:", 4,
193+
cs.getQueue("root").getMetrics().getAggregateVcoresPreempted());
194+
188195
rm1.close();
189196
}
190197

0 commit comments

Comments
 (0)