Skip to content

Commit 35b8441

Browse files
authored
YARN-10949. Simplify AbstractCSQueue#updateMaxAppRelatedField and find a more meaningful name for this method. Contributed by Andras Gyori
1 parent 414d401 commit 35b8441

File tree

6 files changed

+87
-72
lines changed

6 files changed

+87
-72
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/AbstractCSQueue.java

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,53 +1462,6 @@ private Resource getOrInheritMaxResource(Resource resourceByLabel, String label)
14621462
configuredMaxResource, parentMaxResource));
14631463
}
14641464

1465-
void updateMaxAppRelatedField(CapacitySchedulerConfiguration conf,
1466-
LeafQueue leafQueue) {
1467-
int maxApplications = conf.getMaximumApplicationsPerQueue(queuePath);
1468-
int maxGlobalPerQueueApps = conf.getGlobalMaximumApplicationsPerQueue();
1469-
String maxLabel = RMNodeLabelsManager.NO_LABEL;
1470-
1471-
if (maxApplications < 0) {
1472-
for (String label : configuredNodeLabels) {
1473-
int maxApplicationsByLabel = 0;
1474-
if (maxGlobalPerQueueApps > 0) {
1475-
// In absolute mode, should
1476-
// shrink when change to corresponding label capacity.
1477-
maxApplicationsByLabel = this.capacityConfigType
1478-
!= CapacityConfigType.ABSOLUTE_RESOURCE ?
1479-
maxGlobalPerQueueApps :
1480-
(int) (maxGlobalPerQueueApps * queueCapacities
1481-
.getAbsoluteCapacity(label));
1482-
} else {
1483-
maxApplicationsByLabel = (int) (conf.getMaximumSystemApplications()
1484-
* queueCapacities.getAbsoluteCapacity(label));
1485-
}
1486-
if (maxApplicationsByLabel > maxApplications) {
1487-
maxApplications = maxApplicationsByLabel;
1488-
maxLabel = label;
1489-
}
1490-
}
1491-
}
1492-
leafQueue.setMaxApplications(maxApplications);
1493-
1494-
int maxApplicationsPerUser = Math.min(maxApplications,
1495-
(int) (maxApplications
1496-
* (leafQueue.getUsersManager().getUserLimit() / 100.0f)
1497-
* leafQueue.getUsersManager().getUserLimitFactor()));
1498-
if (leafQueue.getUsersManager().getUserLimitFactor() == -1) {
1499-
maxApplicationsPerUser = maxApplications;
1500-
}
1501-
1502-
leafQueue.setMaxApplicationsPerUser(maxApplicationsPerUser);
1503-
LOG.info("LeafQueue:" + leafQueue.getQueuePath() +
1504-
"update max app related, maxApplications="
1505-
+ maxApplications + ", maxApplicationsPerUser="
1506-
+ maxApplicationsPerUser + ", Abs Cap:" + queueCapacities
1507-
.getAbsoluteCapacity(maxLabel) + ", Cap: " + queueCapacities
1508-
.getCapacity(maxLabel) + ", MaxCap : " + queueCapacities
1509-
.getMaximumCapacity(maxLabel));
1510-
}
1511-
15121465
void deriveCapacityFromAbsoluteConfigurations(String label,
15131466
Resource clusterResource) {
15141467
// Update capacity with a float calculated from the parent's minResources

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ private String getNodeLabelPrefix(String queue, String label) {
461461
return getQueuePrefix(queue) + ACCESSIBLE_NODE_LABELS + DOT + label + DOT;
462462
}
463463

464+
public void setMaximumSystemApplications(int numMaxApps) {
465+
setInt(MAXIMUM_SYSTEM_APPLICATIONS, numMaxApps);
466+
}
467+
464468
public int getMaximumSystemApplications() {
465469
int maxApplications =
466470
getInt(MAXIMUM_SYSTEM_APPLICATIONS, DEFAULT_MAXIMUM_SYSTEM_APPLICATIIONS);

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: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.IOException;
2222
import java.util.*;
23-
import java.util.Map.Entry;
2423
import java.util.concurrent.ConcurrentHashMap;
2524
import java.util.concurrent.ConcurrentMap;
2625

@@ -1939,8 +1938,9 @@ public void updateClusterResource(Resource clusterResource,
19391938
updateAbsoluteCapacities();
19401939

19411940
super.updateEffectiveResources(clusterResource);
1942-
super.updateMaxAppRelatedField(csContext.getConfiguration(),
1943-
this);
1941+
1942+
// Update maximum applications for the queue and for users
1943+
updateMaximumApplications(csContext.getConfiguration());
19441944

19451945
updateCurrentResourceLimits(currentResourceLimits, clusterResource);
19461946

@@ -2326,6 +2326,58 @@ public void stopQueue() {
23262326
}
23272327
}
23282328

2329+
void updateMaximumApplications(CapacitySchedulerConfiguration conf) {
2330+
int maxAppsForQueue = conf.getMaximumApplicationsPerQueue(getQueuePath());
2331+
2332+
int maxDefaultPerQueueApps = conf.getGlobalMaximumApplicationsPerQueue();
2333+
int maxSystemApps = conf.getMaximumSystemApplications();
2334+
int baseMaxApplications = maxDefaultPerQueueApps > 0 ?
2335+
Math.min(maxDefaultPerQueueApps, maxSystemApps)
2336+
: maxSystemApps;
2337+
2338+
String maxLabel = RMNodeLabelsManager.NO_LABEL;
2339+
if (maxAppsForQueue < 0) {
2340+
if (maxDefaultPerQueueApps > 0 && this.capacityConfigType
2341+
!= CapacityConfigType.ABSOLUTE_RESOURCE) {
2342+
maxAppsForQueue = baseMaxApplications;
2343+
} else {
2344+
for (String label : configuredNodeLabels) {
2345+
int maxApplicationsByLabel = (int) (baseMaxApplications
2346+
* queueCapacities.getAbsoluteCapacity(label));
2347+
if (maxApplicationsByLabel > maxAppsForQueue) {
2348+
maxAppsForQueue = maxApplicationsByLabel;
2349+
maxLabel = label;
2350+
}
2351+
}
2352+
}
2353+
}
2354+
2355+
setMaxApplications(maxAppsForQueue);
2356+
2357+
updateMaxAppsPerUser();
2358+
2359+
LOG.info("LeafQueue:" + getQueuePath() +
2360+
"update max app related, maxApplications="
2361+
+ maxAppsForQueue + ", maxApplicationsPerUser="
2362+
+ maxApplicationsPerUser + ", Abs Cap:" + queueCapacities
2363+
.getAbsoluteCapacity(maxLabel) + ", Cap: " + queueCapacities
2364+
.getCapacity(maxLabel) + ", MaxCap : " + queueCapacities
2365+
.getMaximumCapacity(maxLabel));
2366+
}
2367+
2368+
private void updateMaxAppsPerUser() {
2369+
int maxAppsPerUser = maxApplications;
2370+
if (getUsersManager().getUserLimitFactor() != -1) {
2371+
int maxApplicationsWithUserLimits = (int) (maxApplications
2372+
* (getUsersManager().getUserLimit() / 100.0f)
2373+
* getUsersManager().getUserLimitFactor());
2374+
maxAppsPerUser = Math.min(maxApplications,
2375+
maxApplicationsWithUserLimits);
2376+
}
2377+
2378+
setMaxApplicationsPerUser(maxAppsPerUser);
2379+
}
2380+
23292381
/**
23302382
* Get all valid users in this queue.
23312383
* @return user list

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,8 @@ public RMNodeLabelsManager createNodeLabelManager() {
870870
+ "submission of application: " + app3.getApplicationId(),
871871
app3.getDiagnostics().toString());
872872

873-
// based on Global limit of queue usert application is rejected
874-
RMApp app11 = MockRMAppSubmitter.submit(rm,
873+
// based on per user max app settings, app should be rejected instantly
874+
RMApp app13 = MockRMAppSubmitter.submit(rm,
875875
MockRMAppSubmissionData.Builder.createWithMemory(GB, rm)
876876
.withAppName("app")
877877
.withUser("user")
@@ -880,36 +880,36 @@ public RMNodeLabelsManager createNodeLabelManager() {
880880
.withWaitForAppAcceptedState(false)
881881
.build());
882882
rm.drainEvents();
883-
rm.waitForState(app11.getApplicationId(), RMAppState.ACCEPTED);
884-
assertEquals(RMAppState.ACCEPTED, app11.getState());
885-
RMApp app12 = MockRMAppSubmitter.submit(rm,
883+
rm.waitForState(app13.getApplicationId(), RMAppState.FAILED);
884+
assertEquals(RMAppState.FAILED, app13.getState());
885+
assertEquals(
886+
"org.apache.hadoop.security.AccessControlException: Queue"
887+
+ " root.d already has 0 applications from user user cannot"
888+
+ " accept submission of application: " + app13.getApplicationId(),
889+
app13.getDiagnostics().toString());
890+
891+
RMApp app11 = MockRMAppSubmitter.submit(rm,
886892
MockRMAppSubmissionData.Builder.createWithMemory(GB, rm)
887893
.withAppName("app")
888-
.withUser("user")
894+
.withUser("user2")
889895
.withAcls(null)
890-
.withQueue("d")
896+
.withQueue("a2")
891897
.withWaitForAppAcceptedState(false)
892898
.build());
893899
rm.drainEvents();
894-
rm.waitForState(app12.getApplicationId(), RMAppState.ACCEPTED);
895-
assertEquals(RMAppState.ACCEPTED, app12.getState());
896-
RMApp app13 = MockRMAppSubmitter.submit(rm,
900+
rm.waitForState(app11.getApplicationId(), RMAppState.ACCEPTED);
901+
assertEquals(RMAppState.ACCEPTED, app11.getState());
902+
RMApp app12 = MockRMAppSubmitter.submit(rm,
897903
MockRMAppSubmissionData.Builder.createWithMemory(GB, rm)
898904
.withAppName("app")
899-
.withUser("user")
905+
.withUser("user2")
900906
.withAcls(null)
901-
.withQueue("d")
907+
.withQueue("a2")
902908
.withWaitForAppAcceptedState(false)
903909
.build());
904910
rm.drainEvents();
905-
rm.waitForState(app13.getApplicationId(), RMAppState.FAILED);
906-
assertEquals(RMAppState.FAILED, app13.getState());
907-
assertEquals(
908-
"org.apache.hadoop.security.AccessControlException: Queue"
909-
+ " root.d already has 2 applications from user user cannot"
910-
+ " accept submission of application: " + app13.getApplicationId(),
911-
app13.getDiagnostics().toString());
912-
911+
rm.waitForState(app12.getApplicationId(), RMAppState.ACCEPTED);
912+
assertEquals(RMAppState.ACCEPTED, app12.getState());
913913
// based on system max limit application is rejected
914914
RMApp app14 = MockRMAppSubmitter.submit(rm,
915915
MockRMAppSubmissionData.Builder.createWithMemory(GB, rm)
@@ -938,7 +938,6 @@ public RMNodeLabelsManager createNodeLabelManager() {
938938
app15.getDiagnostics().toString());
939939

940940
rm.killApp(app2.getApplicationId());
941-
rm.killApp(app11.getApplicationId());
942941
rm.killApp(app13.getApplicationId());
943942
rm.killApp(app14.getApplicationId());
944943
rm.stop();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,6 +5137,13 @@ public void testSetupQueueConfigsWithSpecifiedConfiguration()
51375137
assertEquals(1.0, leafQueue.getAbsoluteMaximumCapacity(),
51385138
EPSILON);
51395139

5140+
// limit maximum apps by max system apps
5141+
csConf.setMaximumSystemApplications(15);
5142+
leafQueue.updateClusterResource(Resource.newInstance(0, 0),
5143+
new ResourceLimits(Resource.newInstance(0, 0)));
5144+
5145+
assertEquals(15, leafQueue.getMaxApplications());
5146+
51405147
} finally {
51415148
//revert config changes
51425149
csConf.setNodeLocalityDelay(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ public void testDeriveCapacityFromAbsoluteConfigurations() throws Exception {
11371137
assertEquals(b.getMaxApplications(), b.getMaxApplicationsPerUser());
11381138

11391139
// Set GlobalMaximumApplicationsPerQueue in csConf
1140-
csConf.setGlobalMaximumApplicationsPerQueue(20000);
1140+
csConf.setGlobalMaximumApplicationsPerQueue(8000);
11411141
root.updateClusterResource(clusterResource,
11421142
new ResourceLimits(clusterResource));
11431143

0 commit comments

Comments
 (0)