Skip to content

Commit 570fa2d

Browse files
committed
YARN-9508. YarnConfiguration areNodeLabel enabled is costly in allocation flow. Contributed by Bilwa S T.
1 parent 2de1e30 commit 570fa2d

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ final class DefaultAMSProcessor implements ApplicationMasterServiceProcessor {
117117
private RMContext rmContext;
118118
private ResourceProfilesManager resourceProfilesManager;
119119
private boolean timelineServiceV2Enabled;
120+
private boolean nodelabelsEnabled;
120121

121122
@Override
122123
public void init(ApplicationMasterServiceContext amsContext,
@@ -125,6 +126,8 @@ public void init(ApplicationMasterServiceContext amsContext,
125126
this.resourceProfilesManager = rmContext.getResourceProfilesManager();
126127
this.timelineServiceV2Enabled = YarnConfiguration.
127128
timelineServiceV2Enabled(rmContext.getYarnConfiguration());
129+
this.nodelabelsEnabled = YarnConfiguration
130+
.areNodeLabelsEnabled(rmContext.getYarnConfiguration());
128131
}
129132

130133
@Override
@@ -242,7 +245,7 @@ public void allocate(ApplicationAttemptId appAttemptId,
242245
try {
243246
RMServerUtils.normalizeAndValidateRequests(ask,
244247
maximumCapacity, app.getQueue(),
245-
getScheduler(), getRmContext());
248+
getScheduler(), getRmContext(), nodelabelsEnabled);
246249
} catch (InvalidResourceRequestException e) {
247250
RMAppAttempt rmAppAttempt = app.getRMAppAttempt(appAttemptId);
248251
handleInvalidResourceException(e, rmAppAttempt);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public class RMAppManager implements EventHandler<RMAppManagerEvent>,
9999
private Configuration conf;
100100
private YarnAuthorizationProvider authorizer;
101101
private boolean timelineServiceV2Enabled;
102+
private boolean nodeLabelsEnabled;
102103

103104
public RMAppManager(RMContext context,
104105
YarnScheduler scheduler, ApplicationMasterService masterService,
@@ -121,6 +122,8 @@ public RMAppManager(RMContext context,
121122
this.authorizer = YarnAuthorizationProvider.getInstance(conf);
122123
this.timelineServiceV2Enabled = YarnConfiguration.
123124
timelineServiceV2Enabled(conf);
125+
this.nodeLabelsEnabled = YarnConfiguration
126+
.areNodeLabelsEnabled(rmContext.getYarnConfiguration());
124127
}
125128

126129
/**
@@ -602,7 +605,7 @@ private List<ResourceRequest> validateAndCreateResourceRequest(
602605
Resource maxAllocation = scheduler.getMaximumResourceCapability(queue);
603606
for (ResourceRequest amReq : amReqs) {
604607
SchedulerUtils.normalizeAndValidateRequest(amReq, maxAllocation,
605-
queue, scheduler, isRecovery, rmContext, null);
608+
queue, isRecovery, rmContext, null, nodeLabelsEnabled);
606609

607610
amReq.setCapability(scheduler.getNormalizedResource(
608611
amReq.getCapability(), maxAllocation));

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ private static String validateContainerIdAndVersion(
245245
*/
246246
public static void normalizeAndValidateRequests(List<ResourceRequest> ask,
247247
Resource maximumAllocation, String queueName, YarnScheduler scheduler,
248-
RMContext rmContext) throws InvalidResourceRequestException {
248+
RMContext rmContext, boolean nodeLabelsEnabled)
249+
throws InvalidResourceRequestException {
249250
// Get queue from scheduler
250251
QueueInfo queueInfo = null;
251252
try {
@@ -257,7 +258,7 @@ public static void normalizeAndValidateRequests(List<ResourceRequest> ask,
257258

258259
for (ResourceRequest resReq : ask) {
259260
SchedulerUtils.normalizeAndValidateRequest(resReq, maximumAllocation,
260-
queueName, scheduler, rmContext, queueInfo);
261+
queueName, rmContext, queueInfo, nodeLabelsEnabled);
261262
}
262263
}
263264

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.apache.hadoop.yarn.api.records.Resource;
4343
import org.apache.hadoop.yarn.api.records.ResourceInformation;
4444
import org.apache.hadoop.yarn.api.records.ResourceRequest;
45-
import org.apache.hadoop.yarn.conf.YarnConfiguration;
4645
import org.apache.hadoop.yarn.exceptions.InvalidLabelResourceRequestException;
4746
import org.apache.hadoop.yarn.exceptions.InvalidResourceRequestException;
4847
import org.apache.hadoop.yarn.exceptions.InvalidResourceRequestException
@@ -259,12 +258,12 @@ private static void normalizeNodeLabelExpressionInRequest(
259258
}
260259

261260
public static void normalizeAndValidateRequest(ResourceRequest resReq,
262-
Resource maximumAllocation, String queueName, YarnScheduler scheduler,
263-
boolean isRecovery, RMContext rmContext, QueueInfo queueInfo)
264-
throws InvalidResourceRequestException {
261+
Resource maximumAllocation, String queueName, boolean isRecovery,
262+
RMContext rmContext, QueueInfo queueInfo, boolean nodeLabelsEnabled)
263+
throws InvalidResourceRequestException {
265264
Configuration conf = rmContext.getYarnConfiguration();
266265
// If Node label is not enabled throw exception
267-
if (null != conf && !YarnConfiguration.areNodeLabelsEnabled(conf)) {
266+
if (null != conf && !nodeLabelsEnabled) {
268267
String labelExp = resReq.getNodeLabelExpression();
269268
if (!(RMNodeLabelsManager.NO_LABEL.equals(labelExp)
270269
|| null == labelExp)) {
@@ -280,7 +279,8 @@ public static void normalizeAndValidateRequest(ResourceRequest resReq,
280279
}
281280
if (null == queueInfo) {
282281
try {
283-
queueInfo = scheduler.getQueueInfo(queueName, false, false);
282+
queueInfo = rmContext.getScheduler().getQueueInfo(queueName, false,
283+
false);
284284
} catch (IOException e) {
285285
//Queue may not exist since it could be auto-created in case of
286286
// dynamic queues
@@ -294,11 +294,11 @@ public static void normalizeAndValidateRequest(ResourceRequest resReq,
294294
}
295295

296296
public static void normalizeAndValidateRequest(ResourceRequest resReq,
297-
Resource maximumAllocation, String queueName, YarnScheduler scheduler,
298-
RMContext rmContext, QueueInfo queueInfo)
299-
throws InvalidResourceRequestException {
300-
normalizeAndValidateRequest(resReq, maximumAllocation, queueName, scheduler,
301-
false, rmContext, queueInfo);
297+
Resource maximumAllocation, String queueName, RMContext rmContext,
298+
QueueInfo queueInfo, boolean nodeLabelsEnabled)
299+
throws InvalidResourceRequestException {
300+
normalizeAndValidateRequest(resReq, maximumAllocation, queueName, false,
301+
rmContext, queueInfo, nodeLabelsEnabled);
302302
}
303303

304304
/**

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public ConcurrentMap<ApplicationId, RMApp> getRMApps() {
204204
metricsPublisher = mock(SystemMetricsPublisher.class);
205205
context.setSystemMetricsPublisher(metricsPublisher);
206206
context.setRMApplicationHistoryWriter(writer);
207+
((RMContextImpl)context).setYarnConfiguration(new YarnConfiguration());
207208
return context;
208209
}
209210

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,8 @@ private static void normalizeAndvalidateRequest(ResourceRequest resReq,
10201020
Resource maxAllocation)
10211021
throws InvalidResourceRequestException {
10221022
SchedulerUtils.normalizeAndValidateRequest(resReq, maxAllocation, queueName,
1023-
scheduler, rmContext, null);
1023+
rmContext, null, YarnConfiguration
1024+
.areNodeLabelsEnabled(rmContext.getYarnConfiguration()));
10241025
}
10251026

10261027
private static class InvalidResourceRequestExceptionMessageGenerator {

0 commit comments

Comments
 (0)