YARN-9756: Create metric that sums total memory/vcores preempted per round. Contributed by Manikandan R (manirajv06).

(cherry picked from commit d562050cec)
This commit is contained in:
Eric E Payne 2019-08-28 20:53:43 +00:00
parent f73842780e
commit 51896ff7e6
3 changed files with 29 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceAudience.Private; import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -76,6 +77,10 @@ public class QueueMetrics implements MetricsSource {
@Metric("# of active applications") MutableGaugeInt activeApplications; @Metric("# of active applications") MutableGaugeInt activeApplications;
@Metric("App Attempt First Container Allocation Delay") @Metric("App Attempt First Container Allocation Delay")
MutableRate appAttemptFirstContainerAllocationDelay; MutableRate appAttemptFirstContainerAllocationDelay;
@Metric("Aggregate total of preempted memory MB")
MutableCounterLong aggregateMemoryMBPreempted;
@Metric("Aggregate total of preempted vcores")
MutableCounterLong aggregateVcoresPreempted;
//Metrics updated only for "default" partition //Metrics updated only for "default" partition
@Metric("Allocated memory in MB") MutableGaugeLong allocatedMB; @Metric("Allocated memory in MB") MutableGaugeLong allocatedMB;
@ -552,6 +557,14 @@ public class QueueMetrics implements MetricsSource {
} }
} }
public void updatePreemptedResources(Resource res) {
aggregateMemoryMBPreempted.incr(res.getMemorySize());
aggregateVcoresPreempted.incr(res.getVirtualCores());
if (parent != null) {
parent.updatePreemptedResources(res);
}
}
public void reserveResource(String partition, String user, Resource res) { public void reserveResource(String partition, String user, Resource res) {
if(partition == null || partition.equals(RMNodeLabelsManager.NO_LABEL)) { if(partition == null || partition.equals(RMNodeLabelsManager.NO_LABEL)) {
reserveResource(user, res); reserveResource(user, res);
@ -732,4 +745,14 @@ public class QueueMetrics implements MetricsSource {
public long getAggregatePreemptedContainers() { public long getAggregatePreemptedContainers() {
return aggregateContainersPreempted.value(); return aggregateContainersPreempted.value();
} }
@VisibleForTesting
public long getAggregateMemoryMBPreempted() {
return aggregateMemoryMBPreempted.value();
}
@VisibleForTesting
public long getAggregateVcoresPreempted() {
return aggregateVcoresPreempted.value();
}
} }

View File

@ -1977,6 +1977,7 @@ public class CapacityScheduler extends
/ DateUtils.MILLIS_PER_SECOND; / DateUtils.MILLIS_PER_SECOND;
qMetrics.updatePreemptedMemoryMBSeconds(mbSeconds); qMetrics.updatePreemptedMemoryMBSeconds(mbSeconds);
qMetrics.updatePreemptedVcoreSeconds(vcSeconds); qMetrics.updatePreemptedVcoreSeconds(vcSeconds);
qMetrics.updatePreemptedResources(containerResource);
} }
@Lock(Lock.NoLock.class) @Lock(Lock.NoLock.class)

View File

@ -185,6 +185,11 @@ public class TestCapacitySchedulerSurgicalPreemption
Assert.assertEquals("Number of preempted containers incorrectly recorded:", Assert.assertEquals("Number of preempted containers incorrectly recorded:",
4, cs.getQueue("root").getMetrics().getAggregatePreemptedContainers()); 4, cs.getQueue("root").getMetrics().getAggregatePreemptedContainers());
Assert.assertEquals("Amount of preempted memory incorrectly recorded:",
4 * GB, cs.getQueue("root").getMetrics().getAggregateMemoryMBPreempted());
Assert.assertEquals("Number of preempted vcores incorrectly recorded:",
4, cs.getQueue("root").getMetrics().getAggregateVcoresPreempted());
rm1.close(); rm1.close();
} }