Skip to content

Commit 12c8161

Browse files
author
Giovanni Matteo Fumarola
committed
YARN-9505. Add container allocation latency for Opportunistic Scheduler. Contributed by Abhishek Modi.
1 parent 3e5e5b0 commit 12c8161

File tree

4 files changed

+169
-128
lines changed

4 files changed

+169
-128
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/metrics/OpportunisticSchedulerMetrics.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.hadoop.metrics2.lib.MetricsRegistry;
2929
import org.apache.hadoop.metrics2.lib.MutableCounterLong;
3030
import org.apache.hadoop.metrics2.lib.MutableGaugeInt;
31+
import org.apache.hadoop.metrics2.lib.MutableQuantiles;
3132

3233
import java.util.concurrent.atomic.AtomicBoolean;
3334

@@ -86,6 +87,9 @@ private static void registerMetrics() {
8687
@Metric("Aggregate # of allocated off-switch opportunistic containers")
8788
MutableCounterLong aggregateOffSwitchOContainersAllocated;
8889

90+
@Metric("Aggregate latency for opportunistic container allocation")
91+
MutableQuantiles allocateLatencyOQuantiles;
92+
8993
@VisibleForTesting
9094
public int getAllocatedContainers() {
9195
return allocatedOContainers.value();
@@ -138,4 +142,8 @@ public void incrRackLocalOppContainers() {
138142
public void incrOffSwitchOppContainers() {
139143
aggregateOffSwitchOContainersAllocated.incr();
140144
}
145+
146+
public void addAllocateOLatencyEntry(long latency) {
147+
allocateLatencyOQuantiles.add(latency);
148+
}
141149
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/scheduler/OpportunisticContainerAllocator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.commons.lang3.StringUtils;
2323
import org.apache.hadoop.net.NetUtils;
2424
import org.apache.hadoop.security.SecurityUtil;
25+
import org.apache.hadoop.util.Time;
2526
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
2627
import org.apache.hadoop.yarn.api.records.Container;
2728
import org.apache.hadoop.yarn.api.records.ContainerId;
@@ -241,9 +242,15 @@ static class EnrichedResourceRequest {
241242
private final Map<String, AtomicInteger> nodeLocations = new HashMap<>();
242243
private final Map<String, AtomicInteger> rackLocations = new HashMap<>();
243244
private final ResourceRequest request;
245+
private final long timestamp;
244246

245247
EnrichedResourceRequest(ResourceRequest request) {
246248
this.request = request;
249+
timestamp = Time.monotonicNow();
250+
}
251+
252+
long getTimestamp() {
253+
return timestamp;
247254
}
248255

249256
ResourceRequest getRequest() {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/scheduler/OpportunisticContainerContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818

1919
package org.apache.hadoop.yarn.server.scheduler;
2020

21+
import com.google.common.annotations.VisibleForTesting;
22+
import org.apache.hadoop.util.Time;
2123
import org.apache.hadoop.yarn.api.records.Resource;
2224
import org.apache.hadoop.yarn.api.records.ResourceRequest;
2325
import org.apache.hadoop.yarn.server.api.protocolrecords.RemoteNode;
26+
import org.apache.hadoop.yarn.server.metrics.OpportunisticSchedulerMetrics;
2427
import org.slf4j.Logger;
2528
import org.slf4j.LoggerFactory;
2629

@@ -191,7 +194,14 @@ public void matchAllocationToOutstandingRequest(Resource capability,
191194
err.removeLocation(allocation.getResourceName());
192195
}
193196
}
197+
getOppSchedulerMetrics().addAllocateOLatencyEntry(
198+
Time.monotonicNow() - err.getTimestamp());
194199
}
195200
}
196201
}
202+
203+
@VisibleForTesting
204+
OpportunisticSchedulerMetrics getOppSchedulerMetrics() {
205+
return OpportunisticSchedulerMetrics.getMetrics();
206+
}
197207
}

0 commit comments

Comments
 (0)