Exemplo n.º 1
0
 internal CapacitySchedulerLeafQueueInfo(LeafQueue q)
     : base(q)
 {
     // To add another level in the XML
     numActiveApplications  = q.GetNumActiveApplications();
     numPendingApplications = q.GetNumPendingApplications();
     numContainers          = q.GetNumContainers();
     maxApplications        = q.GetMaxApplications();
     maxApplicationsPerUser = q.GetMaxApplicationsPerUser();
     userLimit           = q.GetUserLimit();
     users               = new UsersInfo(q.GetUsers());
     userLimitFactor     = q.GetUserLimitFactor();
     AMResourceLimit     = new ResourceInfo(q.GetAMResourceLimit());
     usedAMResource      = new ResourceInfo(q.GetQueueResourceUsage().GetAMUsed());
     userAMResourceLimit = new ResourceInfo(q.GetUserAMResourceLimit());
     preemptionDisabled  = q.GetPreemptionDisabled();
 }
Exemplo n.º 2
0
        public virtual void TestLimitsComputation()
        {
            CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration();

            SetupQueueConfiguration(csConf);
            YarnConfiguration        conf      = new YarnConfiguration();
            CapacitySchedulerContext csContext = Org.Mockito.Mockito.Mock <CapacitySchedulerContext
                                                                           >();

            Org.Mockito.Mockito.When(csContext.GetConfiguration()).ThenReturn(csConf);
            Org.Mockito.Mockito.When(csContext.GetConf()).ThenReturn(conf);
            Org.Mockito.Mockito.When(csContext.GetMinimumResourceCapability()).ThenReturn(Resources
                                                                                          .CreateResource(Gb, 1));
            Org.Mockito.Mockito.When(csContext.GetMaximumResourceCapability()).ThenReturn(Resources
                                                                                          .CreateResource(16 * Gb, 16));
            Org.Mockito.Mockito.When(csContext.GetApplicationComparator()).ThenReturn(CapacityScheduler
                                                                                      .applicationComparator);
            Org.Mockito.Mockito.When(csContext.GetQueueComparator()).ThenReturn(CapacityScheduler
                                                                                .queueComparator);
            Org.Mockito.Mockito.When(csContext.GetResourceCalculator()).ThenReturn(resourceCalculator
                                                                                   );
            Org.Mockito.Mockito.When(csContext.GetRMContext()).ThenReturn(rmContext);
            // Say cluster has 100 nodes of 16G each
            Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource
                                                                              (100 * 16 * Gb, 100 * 16);
            Org.Mockito.Mockito.When(csContext.GetClusterResource()).ThenReturn(clusterResource
                                                                                );
            IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>();
            CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, "root", queues
                                                        , queues, TestUtils.spyHook);
            LeafQueue queue = (LeafQueue)queues[A];

            Log.Info("Queue 'A' -" + " AMResourceLimit=" + queue.GetAMResourceLimit() + " UserAMResourceLimit="
                     + queue.GetUserAMResourceLimit());
            NUnit.Framework.Assert.AreEqual(queue.GetAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                            .NewInstance(160 * Gb, 1));
            NUnit.Framework.Assert.AreEqual(queue.GetUserAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                            .NewInstance(80 * Gb, 1));
            NUnit.Framework.Assert.AreEqual((int)(clusterResource.GetMemory() * queue.GetAbsoluteCapacity
                                                      ()), queue.GetMetrics().GetAvailableMB());
            // Add some nodes to the cluster & test new limits
            clusterResource = Resources.CreateResource(120 * 16 * Gb);
            root.UpdateClusterResource(clusterResource, new ResourceLimits(clusterResource));
            NUnit.Framework.Assert.AreEqual(queue.GetAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                            .NewInstance(192 * Gb, 1));
            NUnit.Framework.Assert.AreEqual(queue.GetUserAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                            .NewInstance(96 * Gb, 1));
            NUnit.Framework.Assert.AreEqual((int)(clusterResource.GetMemory() * queue.GetAbsoluteCapacity
                                                      ()), queue.GetMetrics().GetAvailableMB());
            // should return -1 if per queue setting not set
            NUnit.Framework.Assert.AreEqual((int)CapacitySchedulerConfiguration.Undefined, csConf
                                            .GetMaximumApplicationsPerQueue(queue.GetQueuePath()));
            int expectedMaxApps = (int)(CapacitySchedulerConfiguration.DefaultMaximumSystemApplicatiions
                                        * queue.GetAbsoluteCapacity());

            NUnit.Framework.Assert.AreEqual(expectedMaxApps, queue.GetMaxApplications());
            int expectedMaxAppsPerUser = (int)(expectedMaxApps * (queue.GetUserLimit() / 100.0f
                                                                  ) * queue.GetUserLimitFactor());

            NUnit.Framework.Assert.AreEqual(expectedMaxAppsPerUser, queue.GetMaxApplicationsPerUser
                                                ());
            // should default to global setting if per queue setting not set
            NUnit.Framework.Assert.AreEqual((long)CapacitySchedulerConfiguration.DefaultMaximumApplicationmastersResourcePercent
                                            , (long)csConf.GetMaximumApplicationMasterResourcePerQueuePercent(queue.GetQueuePath
                                                                                                                  ()));
            // Change the per-queue max AM resources percentage.
            csConf.SetFloat("yarn.scheduler.capacity." + queue.GetQueuePath() + ".maximum-am-resource-percent"
                            , 0.5f);
            // Re-create queues to get new configs.
            queues = new Dictionary <string, CSQueue>();
            root   = CapacityScheduler.ParseQueue(csContext, csConf, null, "root", queues, queues
                                                  , TestUtils.spyHook);
            clusterResource = Resources.CreateResource(100 * 16 * Gb);
            queue           = (LeafQueue)queues[A];
            NUnit.Framework.Assert.AreEqual((long)0.5, (long)csConf.GetMaximumApplicationMasterResourcePerQueuePercent
                                                (queue.GetQueuePath()));
            NUnit.Framework.Assert.AreEqual(queue.GetAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                            .NewInstance(800 * Gb, 1));
            NUnit.Framework.Assert.AreEqual(queue.GetUserAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                            .NewInstance(400 * Gb, 1));
            // Change the per-queue max applications.
            csConf.SetInt("yarn.scheduler.capacity." + queue.GetQueuePath() + ".maximum-applications"
                          , 9999);
            // Re-create queues to get new configs.
            queues = new Dictionary <string, CSQueue>();
            root   = CapacityScheduler.ParseQueue(csContext, csConf, null, "root", queues, queues
                                                  , TestUtils.spyHook);
            queue = (LeafQueue)queues[A];
            NUnit.Framework.Assert.AreEqual(9999, (int)csConf.GetMaximumApplicationsPerQueue(
                                                queue.GetQueuePath()));
            NUnit.Framework.Assert.AreEqual(9999, queue.GetMaxApplications());
            expectedMaxAppsPerUser = (int)(9999 * (queue.GetUserLimit() / 100.0f) * queue.GetUserLimitFactor
                                               ());
            NUnit.Framework.Assert.AreEqual(expectedMaxAppsPerUser, queue.GetMaxApplicationsPerUser
                                                ());
        }
Exemplo n.º 3
0
        public virtual void TestAMResourceLimit()
        {
            string user_0 = "user_0";
            string user_1 = "user_1";

            // This uses the default 10% of cluster value for the max am resources
            // which are allowed, at 80GB = 8GB for AM's at the queue level.  The user
            // am limit is 4G initially (based on the queue absolute capacity)
            // when there is only 1 user, and drops to 2G (the userlimit) when there
            // is a second user
            Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                          .NewInstance(80 * Gb, 40);
            queue.UpdateClusterResource(clusterResource, new ResourceLimits(clusterResource));
            ActiveUsersManager activeUsersManager = Org.Mockito.Mockito.Mock <ActiveUsersManager
                                                                              >();

            Org.Mockito.Mockito.When(queue.GetActiveUsersManager()).ThenReturn(activeUsersManager
                                                                               );
            NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                (8 * Gb, 1), queue.GetAMResourceLimit());
            NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                (4 * Gb, 1), queue.GetUserAMResourceLimit());
            // Two apps for user_0, both start
            int ApplicationId      = 0;
            FiCaSchedulerApp app_0 = GetMockApplication(ApplicationId++, user_0, Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                        .NewInstance(2 * Gb, 1));

            queue.SubmitApplicationAttempt(app_0, user_0);
            NUnit.Framework.Assert.AreEqual(1, queue.GetNumActiveApplications());
            NUnit.Framework.Assert.AreEqual(0, queue.GetNumPendingApplications());
            NUnit.Framework.Assert.AreEqual(1, queue.GetNumActiveApplications(user_0));
            NUnit.Framework.Assert.AreEqual(0, queue.GetNumPendingApplications(user_0));
            Org.Mockito.Mockito.When(activeUsersManager.GetNumActiveUsers()).ThenReturn(1);
            FiCaSchedulerApp app_1 = GetMockApplication(ApplicationId++, user_0, Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                        .NewInstance(2 * Gb, 1));

            queue.SubmitApplicationAttempt(app_1, user_0);
            NUnit.Framework.Assert.AreEqual(2, queue.GetNumActiveApplications());
            NUnit.Framework.Assert.AreEqual(0, queue.GetNumPendingApplications());
            NUnit.Framework.Assert.AreEqual(2, queue.GetNumActiveApplications(user_0));
            NUnit.Framework.Assert.AreEqual(0, queue.GetNumPendingApplications(user_0));
            // AMLimits unchanged
            NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                (8 * Gb, 1), queue.GetAMResourceLimit());
            NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                (4 * Gb, 1), queue.GetUserAMResourceLimit());
            // One app for user_1, starts
            FiCaSchedulerApp app_2 = GetMockApplication(ApplicationId++, user_1, Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                        .NewInstance(2 * Gb, 1));

            queue.SubmitApplicationAttempt(app_2, user_1);
            NUnit.Framework.Assert.AreEqual(3, queue.GetNumActiveApplications());
            NUnit.Framework.Assert.AreEqual(0, queue.GetNumPendingApplications());
            NUnit.Framework.Assert.AreEqual(1, queue.GetNumActiveApplications(user_1));
            NUnit.Framework.Assert.AreEqual(0, queue.GetNumPendingApplications(user_1));
            Org.Mockito.Mockito.When(activeUsersManager.GetNumActiveUsers()).ThenReturn(2);
            // Now userAMResourceLimit drops to the queue configured 50% as there is
            // another user active
            NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                (8 * Gb, 1), queue.GetAMResourceLimit());
            NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                (2 * Gb, 1), queue.GetUserAMResourceLimit());
            // Second user_1 app cannot start
            FiCaSchedulerApp app_3 = GetMockApplication(ApplicationId++, user_1, Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                        .NewInstance(2 * Gb, 1));

            queue.SubmitApplicationAttempt(app_3, user_1);
            NUnit.Framework.Assert.AreEqual(3, queue.GetNumActiveApplications());
            NUnit.Framework.Assert.AreEqual(1, queue.GetNumPendingApplications());
            NUnit.Framework.Assert.AreEqual(1, queue.GetNumActiveApplications(user_1));
            NUnit.Framework.Assert.AreEqual(1, queue.GetNumPendingApplications(user_1));
            // Now finish app so another should be activated
            queue.FinishApplicationAttempt(app_2, A);
            NUnit.Framework.Assert.AreEqual(3, queue.GetNumActiveApplications());
            NUnit.Framework.Assert.AreEqual(0, queue.GetNumPendingApplications());
            NUnit.Framework.Assert.AreEqual(1, queue.GetNumActiveApplications(user_1));
            NUnit.Framework.Assert.AreEqual(0, queue.GetNumPendingApplications(user_1));
        }