diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerPerf.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerPerf.java index 09f9fd2..864c3ba 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerPerf.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerPerf.java @@ -34,6 +34,7 @@ import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.server.resourcemanager.MockNodes; import org.apache.hadoop.yarn.server.resourcemanager.MockRM; +import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppImpl; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptImpl; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptMetrics; @@ -58,6 +59,9 @@ import java.util.PriorityQueue; import static org.apache.hadoop.yarn.server.resourcemanager.resource.TestResourceProfiles.TEST_CONF_RESET_RESOURCE_TYPES; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -90,7 +94,7 @@ private void testUserLimitThroughputWithNumberOfResourceTypes( } // Since this is more of a performance unit test, only run if - // RunUserLimitThroughput is set (-DRunUserLimitThroughput=true) + // RunCapacitySchedulerPerfTests is set (-DRunCapacitySchedulerPerfTests=true) Assume.assumeTrue(Boolean.valueOf( System.getProperty("RunCapacitySchedulerPerfTests"))); @@ -256,4 +260,232 @@ public void testUserLimitThroughputForFourResources() throws Exception { public void testUserLimitThroughputForFiveResources() throws Exception { testUserLimitThroughputWithNumberOfResourceTypes(5); } + + // This test is run only when when -DRunCapacitySchedulerPerfTests=true is set on + // the command line. In addition, this test has tunables for the following: + // Number of queues: -DNumberOfQueues (default=100) + // Number of total apps: -DNumberOfApplications (default=200) + // Percentage of queues with apps: -DPercentActiveQueues (default=100) + // E.G.: + // mvn test -Dtest=TestCapacitySchedulerPerf#testUserLimitThroughputWithManyQueues -DRunCapacitySchedulerPerfTests=true -DNumberOfQueues=50 -DNumberOfApplications=200 -DPercentActiveQueues=100 + @Test (timeout = 1800000) + public void testUserLimitThroughputWithManyQueues() throws Exception { + // Since this is more of a performance unit test, only run if + // RunCapacitySchedulerPerfTests is set (-DRunCapacitySchedulerPerfTests=true) + Assume.assumeTrue(Boolean.valueOf( + System.getProperty("RunCapacitySchedulerPerfTests"))); + + int numQueues = 40; + if (Integer.getInteger("NumberOfQueues") != null) { + numQueues = Integer.getInteger("NumberOfQueues"); + } + int pctActiveQueues = 100; + if (Integer.getInteger("PercentActiveQueues") != null) { + pctActiveQueues = Integer.getInteger("PercentActiveQueues"); + } + int appCount = 100; + if (Integer.getInteger("NumberOfApplications") != null) { + appCount = Integer.getInteger("NumberOfApplications"); + } + + System.out.print("\n Number of queues: " + numQueues + + "\n Number of applications: " + appCount + + "\n Percentage of active queues: " + pctActiveQueues + + "\n"); + + final int activeQueues = (int) (numQueues * (pctActiveQueues/100f)); + final int totalApps = appCount + activeQueues; + // extra apps to get started with user limit + + CapacitySchedulerConfiguration csconf = + createCSConfWithManyQueues(numQueues); + + YarnConfiguration conf = new YarnConfiguration(csconf); + conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, + ResourceScheduler.class); + + MockRM rm = new MockRM(conf); + rm.start(); + + CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); + + LeafQueue[] lqs = new LeafQueue[numQueues]; + for (int i = 0; i < numQueues; i++) { + String queueName = String.format("%03d", i); + LeafQueue qb = (LeafQueue)cs.getQueue(queueName); + qb.setUserLimitFactor((float)100.0); + qb.setupConfigurableCapacities(); + lqs[i] = qb; + } + + SchedulerEvent addAppEvent; + SchedulerEvent addAttemptEvent; + Container container = mock(Container.class); + ApplicationSubmissionContext submissionContext = + mock(ApplicationSubmissionContext.class); + + ApplicationId[] appids = new ApplicationId[totalApps]; + RMAppAttemptImpl[] attempts = new RMAppAttemptImpl[totalApps]; + ApplicationAttemptId[] appAttemptIds = new ApplicationAttemptId[totalApps]; + RMAppImpl[] apps = new RMAppImpl[totalApps]; + RMAppAttemptMetrics[] attemptMetrics = new RMAppAttemptMetrics[totalApps]; + for (int i=0; i limit, not used >= limit + cs.handle(new NodeUpdateSchedulerEvent(node)); + cs.handle(new NodeUpdateSchedulerEvent(node2)); + + // make sure only the extra apps have allocated containers + for (int i=0;i queue = new PriorityQueue<>(topn, + Collections.reverseOrder()); + + long n = Time.monotonicNow(); + long timespent = 0; + for (int i = 0; i < iterations; i+=2) { + if (i > 0 && i % printInterval == 0){ + long ts = (Time.monotonicNow() - n); + if (queue.size() < topn) { + queue.offer(ts); + } else { + Long last = queue.peek(); + if (last > ts) { + queue.poll(); + queue.offer(ts); + } + } + System.out.println(i + " " + (numerator / ts)); + n= Time.monotonicNow(); + } + cs.handle(new NodeUpdateSchedulerEvent(node)); + cs.handle(new NodeUpdateSchedulerEvent(node2)); + } + timespent=0; + int entries = queue.size(); + while(queue.size() > 0){ + long l = queue.poll(); + timespent += l; + } + System.out.println("Avg of fastest " + entries + ": " + + numerator / (timespent / entries) + " ops/sec of " + appCount + + " apps on " + pctActiveQueues + "% of " + numQueues + " queues."); + + // make sure only the extra apps have allocated containers + for (int i=0;i