Skip to content

Commit b204aa9

Browse files
author
yangtao.yt
committed
YARN-11781. Implement Dynamic Requests Handling in CapacityScheduler
1 parent 89f9c5a commit b204aa9

File tree

8 files changed

+972
-0
lines changed

8 files changed

+972
-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/CapacityScheduler.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ public Configuration getConf() {
240240

241241
private CSMaxRunningAppsEnforcer maxRunningEnforcer;
242242

243+
private RequestsHandler requestsHandler;
244+
243245
public CapacityScheduler() {
244246
super(CapacityScheduler.class.getName());
245247
this.maxRunningEnforcer = new CSMaxRunningAppsEnforcer(this);
@@ -328,6 +330,7 @@ void initScheduler(Configuration configuration) throws
328330
offswitchPerHeartbeatLimit = this.conf.getOffSwitchPerHeartbeatLimit();
329331

330332
initMultiNodePlacement();
333+
initRequestsHandler();
331334
printSchedulerInitialized();
332335
} finally {
333336
writeLock.unlock();
@@ -455,8 +458,15 @@ public void reinitialize(Configuration newConf, RMContext rmContext,
455458
refreshMaximumAllocation(
456459
ResourceUtils.fetchMaximumAllocationFromConfig(this.conf));
457460
reinitializeQueues(this.conf);
461+
reinitRequestsHandler(this.conf);
458462
} catch (Throwable t) {
459463
this.conf = oldConf;
464+
try {
465+
reinitRequestsHandler(this.conf);
466+
} catch (Throwable innerT) {
467+
LOG.error("Failed to re-init requests handler : {}",
468+
innerT.getMessage(), innerT);
469+
}
460470
reinitializeQueues(this.conf);
461471
refreshMaximumAllocation(
462472
ResourceUtils.fetchMaximumAllocationFromConfig(this.conf));
@@ -1337,6 +1347,26 @@ public Allocation allocate(ApplicationAttemptId applicationAttemptId,
13371347
return EMPTY_ALLOCATION;
13381348
}
13391349

1350+
// Handle requests
1351+
long requestsHandleStartTime = System.currentTimeMillis();
1352+
RequestsHandleResponse handleResponse =
1353+
handleRequests(application, ask, schedulingRequests);
1354+
long requestsHandleElapsedMs =
1355+
System.currentTimeMillis() - requestsHandleStartTime;
1356+
CapacitySchedulerMetrics.getMetrics().addRequestsHandle(
1357+
requestsHandleElapsedMs);
1358+
if (handleResponse != null && handleResponse.isUpdated()) {
1359+
LOG.info("Updated requests: appId={}, elapsedMs={}\n" +
1360+
"ResourceRequests: origin={}, updated={}\n" +
1361+
"SchedulingRequests: origin={}, updated={}",
1362+
applicationAttemptId.getApplicationId(),
1363+
requestsHandleElapsedMs,
1364+
ask, handleResponse.getResourceRequests(),
1365+
schedulingRequests, handleResponse.getSchedulingRequests());
1366+
ask = handleResponse.getResourceRequests();
1367+
schedulingRequests = handleResponse.getSchedulingRequests();
1368+
}
1369+
13401370
// Handle all container updates
13411371
handleContainerUpdates(application, updateRequests);
13421372

@@ -3642,4 +3672,23 @@ public int compare(FiCaSchedulerApp app1, FiCaSchedulerApp app2) {
36423672
}
36433673
}
36443674
}
3675+
3676+
/**
3677+
* initialize / reinitialize / handleRequests methods for RequestsHandler.
3678+
*/
3679+
private void initRequestsHandler() throws IOException, YarnException {
3680+
requestsHandler = new RequestsHandler(rmContext);
3681+
reinitRequestsHandler(this.conf);
3682+
}
3683+
3684+
private void reinitRequestsHandler(Configuration conf)
3685+
throws IOException, YarnException {
3686+
requestsHandler.initialize(conf);
3687+
}
3688+
3689+
protected RequestsHandleResponse handleRequests(FiCaSchedulerApp app,
3690+
List<ResourceRequest> resourceRequests,
3691+
List<SchedulingRequest> schedulingRequests) {
3692+
return requestsHandler.handle(app, resourceRequests, schedulingRequests);
3693+
}
36453694
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,17 @@ public class CapacitySchedulerConfiguration extends ReservationSchedulerConfigur
430430
public static final String MAPPING_RULE_FORMAT_DEFAULT =
431431
MAPPING_RULE_FORMAT_LEGACY;
432432

433+
public static final String REQUEST_HANDLER_PREFIX =
434+
PREFIX + "request-handler.";
435+
436+
public static final String REQUEST_HANDLER_ENABLED =
437+
REQUEST_HANDLER_PREFIX + "enabled";
438+
439+
public static final boolean DEFAULT_REQUEST_HANDLER_ENABLED = false;
440+
441+
public static final String REQUEST_HANDLER_UPDATES =
442+
REQUEST_HANDLER_PREFIX + "updates";
443+
433444
private static final QueueCapacityConfigParser queueCapacityConfigParser
434445
= new QueueCapacityConfigParser();
435446
private static final String LEGACY_QUEUE_MODE_ENABLED = PREFIX + "legacy-queue-mode.enabled";

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class CapacitySchedulerMetrics {
5252
@Metric("Scheduler node update") MutableRate nodeUpdate;
5353
@Metric("Scheduler node heartbeat interval") MutableQuantiles
5454
schedulerNodeHBInterval;
55+
@Metric("Requests handle") MutableRate requestsHandle;
5556

5657
private static volatile CapacitySchedulerMetrics INSTANCE = null;
5758
private static MetricsRegistry registry;
@@ -128,4 +129,13 @@ public void addSchedulerNodeHBInterval(long heartbeatInterval) {
128129
public long getNumOfSchedulerNodeHBInterval() {
129130
return this.schedulerNodeHBInterval.getEstimator().getCount();
130131
}
132+
133+
public void addRequestsHandle(long latency) {
134+
this.requestsHandle.add(latency);
135+
}
136+
137+
@VisibleForTesting
138+
public long getNumOfRequestsHandle() {
139+
return this.requestsHandle.lastStat().numSamples();
140+
}
131141
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
2+
3+
import org.apache.hadoop.yarn.api.records.ResourceRequest;
4+
import org.apache.hadoop.yarn.api.records.SchedulingRequest;
5+
6+
import java.util.List;
7+
8+
/**
9+
* Response of the handle method in {@link RequestsHandler}.
10+
*/
11+
public class RequestsHandleResponse {
12+
13+
private final boolean isUpdated;
14+
private final List<ResourceRequest> resourceRequests;
15+
private final List<SchedulingRequest> schedulingRequests;
16+
17+
public RequestsHandleResponse(boolean isUpdated,
18+
List<ResourceRequest> resourceRequests,
19+
List<SchedulingRequest> schedulingRequests) {
20+
this.isUpdated = isUpdated;
21+
this.resourceRequests = resourceRequests;
22+
this.schedulingRequests = schedulingRequests;
23+
}
24+
25+
public List<ResourceRequest> getResourceRequests() {
26+
return resourceRequests;
27+
}
28+
29+
public List<SchedulingRequest> getSchedulingRequests() {
30+
return schedulingRequests;
31+
}
32+
33+
public boolean isUpdated() {
34+
return isUpdated;
35+
}
36+
}

0 commit comments

Comments
 (0)