Skip to content

Commit 62cddc1

Browse files
bibinchundattahussein
authored andcommitted
YARN-9797. LeafQueue#activateApplications should use resourceCalculator#fitsIn. Contributed by Bilwa S T.
1 parent 6933f9b commit 62cddc1

File tree

2 files changed

+87
-4
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src

2 files changed

+87
-4
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/LeafQueue.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,7 @@ protected void activateApplications() {
832832
+ " AM node-partition name " + partitionName);
833833
}
834834

835-
if (!Resources.lessThanOrEqual(resourceCalculator, lastClusterResource,
836-
amIfStarted, amLimit)) {
835+
if (!resourceCalculator.fitsIn(amIfStarted, amLimit)) {
837836
if (getNumActiveApplications() < 1 || (Resources.lessThanOrEqual(
838837
resourceCalculator, lastClusterResource,
839838
queueUsage.getAMUsed(partitionName), Resources.none()))) {
@@ -865,8 +864,7 @@ protected void activateApplications() {
865864
application.getAMResource(partitionName),
866865
user.getConsumedAMResources(partitionName));
867866

868-
if (!Resources.lessThanOrEqual(resourceCalculator, lastClusterResource,
869-
userAmIfStarted, userAMLimit)) {
867+
if (!resourceCalculator.fitsIn(userAmIfStarted, userAMLimit)) {
870868
if (getNumActiveApplications() < 1 || (Resources.lessThanOrEqual(
871869
resourceCalculator, lastClusterResource,
872870
queueUsage.getAMUsed(partitionName), Resources.none()))) {

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.hadoop.yarn.api.records.NodeId;
4040
import org.apache.hadoop.yarn.api.records.Priority;
4141
import org.apache.hadoop.yarn.api.records.Resource;
42+
import org.apache.hadoop.yarn.api.records.ResourceInformation;
4243
import org.apache.hadoop.yarn.api.records.ResourceRequest;
4344
import org.apache.hadoop.yarn.conf.YarnConfiguration;
4445
import org.apache.hadoop.yarn.factories.RecordFactory;
@@ -49,6 +50,7 @@
4950
import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
5051
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager;
5152
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
53+
import org.apache.hadoop.yarn.server.resourcemanager.resource.TestResourceProfiles;
5254
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
5355
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
5456
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceLimits;
@@ -59,7 +61,9 @@
5961
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp;
6062
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerNode;
6163
import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator;
64+
import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
6265
import org.apache.hadoop.yarn.util.resource.ResourceCalculator;
66+
import org.apache.hadoop.yarn.util.resource.ResourceUtils;
6367
import org.apache.hadoop.yarn.util.resource.Resources;
6468
import org.junit.Assert;
6569
import org.junit.Before;
@@ -750,4 +754,85 @@ public void testHeadroom() throws Exception {
750754

751755

752756
}
757+
758+
/**
759+
* {@link LeafQueue#activateApplications()} should validate values of all
760+
* resourceTypes before activating application.
761+
*
762+
* @throws Exception
763+
*/
764+
@Test
765+
public void testAMLimitByAllResources() throws Exception {
766+
CapacitySchedulerConfiguration csconf =
767+
new CapacitySchedulerConfiguration();
768+
csconf.setResourceComparator(DominantResourceCalculator.class);
769+
String queueName = "a1";
770+
csconf.setQueues(CapacitySchedulerConfiguration.ROOT,
771+
new String[] {queueName});
772+
csconf.setCapacity("root." + queueName, 100);
773+
774+
ResourceInformation res0 = ResourceInformation.newInstance("memory-mb",
775+
ResourceInformation.MEMORY_MB.getUnits(), GB, Long.MAX_VALUE);
776+
ResourceInformation res1 = ResourceInformation.newInstance("vcores",
777+
ResourceInformation.VCORES.getUnits(), 1, Integer.MAX_VALUE);
778+
ResourceInformation res2 = ResourceInformation.newInstance("gpu",
779+
ResourceInformation.GPUS.getUnits(), 0, Integer.MAX_VALUE);
780+
Map<String, ResourceInformation> riMap = new HashMap<>();
781+
riMap.put(ResourceInformation.MEMORY_URI, res0);
782+
riMap.put(ResourceInformation.VCORES_URI, res1);
783+
riMap.put(ResourceInformation.GPU_URI, res2);
784+
ResourceUtils.initializeResourcesFromResourceInformationMap(riMap);
785+
786+
YarnConfiguration config = new YarnConfiguration(csconf);
787+
config.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
788+
ResourceScheduler.class);
789+
config.setBoolean(TestResourceProfiles.TEST_CONF_RESET_RESOURCE_TYPES,
790+
false);
791+
792+
MockRM rm = new MockRM(config);
793+
rm.start();
794+
795+
Map<String, Long> res = new HashMap<>();
796+
res.put("gpu", 0L);
797+
798+
Resource clusterResource = Resource.newInstance(16 * GB, 64, res);
799+
800+
// Cluster Resource - 16GB, 64vcores
801+
// AMLimit 16384 x .1 mb , 64 x .1 vcore
802+
// Effective AM limit after normalized to minimum resource 2048,7
803+
804+
rm.registerNode("127.0.0.1:1234", clusterResource);
805+
806+
String userName = "user_0";
807+
ResourceScheduler scheduler = rm.getRMContext().getScheduler();
808+
LeafQueue queueA = (LeafQueue) ((CapacityScheduler) scheduler)
809+
.getQueue(queueName);
810+
811+
Resource amResource = Resource.newInstance(GB, 1);
812+
813+
rm.submitApp(amResource, "app-1", userName, null, queueName);
814+
rm.submitApp(amResource, "app-2", userName, null, queueName);
815+
816+
// app-3 should not be activated as amLimit will be reached
817+
// for memory
818+
rm.submitApp(amResource, "app-3", userName, null, queueName);
819+
820+
Assert.assertEquals("PendingApplications should be 1", 1,
821+
queueA.getNumPendingApplications());
822+
Assert.assertEquals("Active applications should be 2", 2,
823+
queueA.getNumActiveApplications());
824+
// AMLimit is 2048,7
825+
Assert.assertEquals(2048,
826+
queueA.getQueueResourceUsage().getAMLimit().getMemorySize());
827+
Assert.assertEquals(7,
828+
queueA.getQueueResourceUsage().getAMLimit().getVirtualCores());
829+
// Used AM Resource is 2048,2
830+
Assert.assertEquals(2048,
831+
queueA.getQueueResourceUsage().getAMUsed().getMemorySize());
832+
Assert.assertEquals(2,
833+
queueA.getQueueResourceUsage().getAMUsed().getVirtualCores());
834+
835+
rm.close();
836+
837+
}
753838
}

0 commit comments

Comments
 (0)