private void DecResourceRequest(Priority priority, string resourceName, Resource
                                        capability)
        {
            IDictionary <string, IDictionary <Resource, ResourceRequest> > remoteRequests = this
                                                                                            .remoteRequestsTable[priority];
            IDictionary <Resource, ResourceRequest> reqMap = remoteRequests[resourceName];

            if (reqMap == null)
            {
                // as we modify the resource requests by filtering out blacklisted hosts
                // when they are added, this value may be null when being
                // decremented
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Not decrementing resource as " + resourceName + " is not present in request table"
                              );
                }
                return;
            }
            ResourceRequest remoteRequest = reqMap[capability];

            if (Log.IsDebugEnabled())
            {
                Log.Debug("BEFORE decResourceRequest:" + " applicationId=" + applicationId.GetId(
                              ) + " priority=" + priority.GetPriority() + " resourceName=" + resourceName + " numContainers="
                          + remoteRequest.GetNumContainers() + " #asks=" + ask.Count);
            }
            if (remoteRequest.GetNumContainers() > 0)
            {
                // based on blacklisting comments above we can end up decrementing more
                // than requested. so guard for that.
                remoteRequest.SetNumContainers(remoteRequest.GetNumContainers() - 1);
            }
            if (remoteRequest.GetNumContainers() == 0)
            {
                Sharpen.Collections.Remove(reqMap, capability);
                if (reqMap.Count == 0)
                {
                    Sharpen.Collections.Remove(remoteRequests, resourceName);
                }
                if (remoteRequests.Count == 0)
                {
                    Sharpen.Collections.Remove(remoteRequestsTable, priority);
                }
            }
            // send the updated resource request to RM
            // send 0 container count requests also to cancel previous requests
            AddResourceRequestToAsk(remoteRequest);
            if (Log.IsDebugEnabled())
            {
                Log.Info("AFTER decResourceRequest:" + " applicationId=" + applicationId.GetId()
                         + " priority=" + priority.GetPriority() + " resourceName=" + resourceName + " numContainers="
                         + remoteRequest.GetNumContainers() + " #asks=" + ask.Count);
            }
        }
Esempio n. 2
0
 private void AddResourceRequest(Priority priority, IDictionary <string, ResourceRequest
                                                                 > requests, string resourceName, Org.Apache.Hadoop.Yarn.Api.Records.Resource capability
                                 )
 {
     lock (this)
     {
         ResourceRequest request = requests[resourceName];
         if (request == null)
         {
             request = BuilderUtils.NewResourceRequest(priority, resourceName, capability, 1);
             requests[resourceName] = request;
         }
         else
         {
             request.SetNumContainers(request.GetNumContainers() + 1);
         }
         // Note this down for next interaction with ResourceManager
         ask.Remove(request);
         ask.AddItem(BuilderUtils.NewResourceRequest(request));
         // clone to ensure the RM doesn't manipulate the same obj
         if (Log.IsDebugEnabled())
         {
             Log.Debug("addResourceRequest: applicationId=" + applicationId.GetId() + " priority="
                       + priority.GetPriority() + " resourceName=" + resourceName + " capability=" + capability
                       + " numContainers=" + request.GetNumContainers() + " #asks=" + ask.Count);
         }
     }
 }
Esempio n. 3
0
        public virtual void TestDelayScheduling()
        {
            FSLeafQueue queue = Org.Mockito.Mockito.Mock <FSLeafQueue>();
            Priority    prio  = Org.Mockito.Mockito.Mock <Priority>();

            Org.Mockito.Mockito.When(prio.GetPriority()).ThenReturn(1);
            double nodeLocalityThreshold = .5;
            double rackLocalityThreshold = .6;
            ApplicationAttemptId applicationAttemptId = CreateAppAttemptId(1, 1);
            RMContext            rmContext            = resourceManager.GetRMContext();
            FSAppAttempt         schedulerApp         = new FSAppAttempt(scheduler, applicationAttemptId, "user1"
                                                                         , queue, null, rmContext);

            // Default level should be node-local
            NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel
                                                (prio, 10, nodeLocalityThreshold, rackLocalityThreshold));
            // First five scheduling opportunities should remain node local
            for (int i = 0; i < 5; i++)
            {
                schedulerApp.AddSchedulingOpportunity(prio);
                NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel
                                                    (prio, 10, nodeLocalityThreshold, rackLocalityThreshold));
            }
            // After five it should switch to rack local
            schedulerApp.AddSchedulingOpportunity(prio);
            NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevel
                                                (prio, 10, nodeLocalityThreshold, rackLocalityThreshold));
            // Manually set back to node local
            schedulerApp.ResetAllowedLocalityLevel(prio, NodeType.NodeLocal);
            schedulerApp.ResetSchedulingOpportunities(prio);
            NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel
                                                (prio, 10, nodeLocalityThreshold, rackLocalityThreshold));
            // Now escalate again to rack-local, then to off-switch
            for (int i_1 = 0; i_1 < 5; i_1++)
            {
                schedulerApp.AddSchedulingOpportunity(prio);
                NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel
                                                    (prio, 10, nodeLocalityThreshold, rackLocalityThreshold));
            }
            schedulerApp.AddSchedulingOpportunity(prio);
            NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevel
                                                (prio, 10, nodeLocalityThreshold, rackLocalityThreshold));
            for (int i_2 = 0; i_2 < 6; i_2++)
            {
                schedulerApp.AddSchedulingOpportunity(prio);
                NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevel
                                                    (prio, 10, nodeLocalityThreshold, rackLocalityThreshold));
            }
            schedulerApp.AddSchedulingOpportunity(prio);
            NUnit.Framework.Assert.AreEqual(NodeType.OffSwitch, schedulerApp.GetAllowedLocalityLevel
                                                (prio, 10, nodeLocalityThreshold, rackLocalityThreshold));
        }
Esempio n. 4
0
        private void AddResourceRequest(Priority priority, string resourceName, Resource
                                        capability, T req, bool relaxLocality, string labelExpression)
        {
            IDictionary <string, SortedDictionary <Resource, AMRMClientImpl.ResourceRequestInfo
                                                   > > remoteRequests = this.remoteRequestsTable[priority];

            if (remoteRequests == null)
            {
                remoteRequests = new Dictionary <string, SortedDictionary <Resource, AMRMClientImpl.ResourceRequestInfo
                                                                           > >();
                this.remoteRequestsTable[priority] = remoteRequests;
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Added priority=" + priority);
                }
            }
            SortedDictionary <Resource, AMRMClientImpl.ResourceRequestInfo> reqMap = remoteRequests
                                                                                     [resourceName];

            if (reqMap == null)
            {
                // capabilities are stored in reverse sorted order. smallest last.
                reqMap = new SortedDictionary <Resource, AMRMClientImpl.ResourceRequestInfo>(new AMRMClientImpl.ResourceReverseMemoryThenCpuComparator
                                                                                                 (this));
                remoteRequests[resourceName] = reqMap;
            }
            AMRMClientImpl.ResourceRequestInfo resourceRequestInfo = reqMap[capability];
            if (resourceRequestInfo == null)
            {
                resourceRequestInfo = new AMRMClientImpl.ResourceRequestInfo(this, priority, resourceName
                                                                             , capability, relaxLocality);
                reqMap[capability] = resourceRequestInfo;
            }
            resourceRequestInfo.remoteRequest.SetNumContainers(resourceRequestInfo.remoteRequest
                                                               .GetNumContainers() + 1);
            if (relaxLocality)
            {
                resourceRequestInfo.containerRequests.AddItem(req);
            }
            if (ResourceRequest.Any.Equals(resourceName))
            {
                resourceRequestInfo.remoteRequest.SetNodeLabelExpression(labelExpression);
            }
            // Note this down for next interaction with ResourceManager
            AddResourceRequestToAsk(resourceRequestInfo.remoteRequest);
            if (Log.IsDebugEnabled())
            {
                Log.Debug("addResourceRequest:" + " applicationId=" + " priority=" + priority.GetPriority
                              () + " resourceName=" + resourceName + " numContainers=" + resourceRequestInfo.remoteRequest
                          .GetNumContainers() + " #asks=" + ask.Count);
            }
        }
Esempio n. 5
0
        public virtual void TestLocalityLevelWithoutDelays()
        {
            FSLeafQueue queue = Org.Mockito.Mockito.Mock <FSLeafQueue>();
            Priority    prio  = Org.Mockito.Mockito.Mock <Priority>();

            Org.Mockito.Mockito.When(prio.GetPriority()).ThenReturn(1);
            RMContext            rmContext            = resourceManager.GetRMContext();
            ApplicationAttemptId applicationAttemptId = CreateAppAttemptId(1, 1);
            FSAppAttempt         schedulerApp         = new FSAppAttempt(scheduler, applicationAttemptId, "user1"
                                                                         , queue, null, rmContext);

            NUnit.Framework.Assert.AreEqual(NodeType.OffSwitch, schedulerApp.GetAllowedLocalityLevel
                                                (prio, 10, -1.0, -1.0));
        }
Esempio n. 6
0
 public virtual void AddResourceRequestSpec(Priority priority, Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                            capability)
 {
     lock (this)
     {
         Org.Apache.Hadoop.Yarn.Api.Records.Resource currentSpec = requestSpec[priority] =
             capability;
         if (currentSpec != null)
         {
             throw new InvalidOperationException("Resource spec already exists for " + "priority "
                                                 + priority.GetPriority() + " - " + currentSpec.GetMemory());
         }
     }
 }
        private void AddResourceRequest(Priority priority, string resourceName, Resource
                                        capability)
        {
            IDictionary <string, IDictionary <Resource, ResourceRequest> > remoteRequests = this
                                                                                            .remoteRequestsTable[priority];

            if (remoteRequests == null)
            {
                remoteRequests = new Dictionary <string, IDictionary <Resource, ResourceRequest> >();
                this.remoteRequestsTable[priority] = remoteRequests;
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Added priority=" + priority);
                }
            }
            IDictionary <Resource, ResourceRequest> reqMap = remoteRequests[resourceName];

            if (reqMap == null)
            {
                reqMap = new Dictionary <Resource, ResourceRequest>();
                remoteRequests[resourceName] = reqMap;
            }
            ResourceRequest remoteRequest = reqMap[capability];

            if (remoteRequest == null)
            {
                remoteRequest = recordFactory.NewRecordInstance <ResourceRequest>();
                remoteRequest.SetPriority(priority);
                remoteRequest.SetResourceName(resourceName);
                remoteRequest.SetCapability(capability);
                remoteRequest.SetNumContainers(0);
                reqMap[capability] = remoteRequest;
            }
            remoteRequest.SetNumContainers(remoteRequest.GetNumContainers() + 1);
            // Note this down for next interaction with ResourceManager
            AddResourceRequestToAsk(remoteRequest);
            if (Log.IsDebugEnabled())
            {
                Log.Debug("addResourceRequest:" + " applicationId=" + applicationId.GetId() + " priority="
                          + priority.GetPriority() + " resourceName=" + resourceName + " numContainers="
                          + remoteRequest.GetNumContainers() + " #asks=" + ask.Count);
            }
        }
Esempio n. 8
0
        private int AssignContainer(FiCaSchedulerNode node, FiCaSchedulerApp application,
                                    Priority priority, int assignableContainers, ResourceRequest request, NodeType type
                                    )
        {
            Log.Debug("assignContainers:" + " node=" + node.GetRMNode().GetNodeAddress() + " application="
                      + application.GetApplicationId().GetId() + " priority=" + priority.GetPriority(
                          ) + " assignableContainers=" + assignableContainers + " request=" + request + " type="
                      + type);
            Org.Apache.Hadoop.Yarn.Api.Records.Resource capability = request.GetCapability();
            int availableContainers = node.GetAvailableResource().GetMemory() / capability.GetMemory
                                          ();
            // TODO: A buggy
            // application
            // with this
            // zero would
            // crash the
            // scheduler.
            int assignedContainers = Math.Min(assignableContainers, availableContainers);

            if (assignedContainers > 0)
            {
                for (int i = 0; i < assignedContainers; ++i)
                {
                    NodeId      nodeId      = node.GetRMNode().GetNodeID();
                    ContainerId containerId = BuilderUtils.NewContainerId(application.GetApplicationAttemptId
                                                                              (), application.GetNewContainerId());
                    // Create the container
                    Container container = BuilderUtils.NewContainer(containerId, nodeId, node.GetRMNode
                                                                        ().GetHttpAddress(), capability, priority, null);
                    // Allocate!
                    // Inform the application
                    RMContainer rmContainer = application.Allocate(type, node, priority, request, container
                                                                   );
                    // Inform the node
                    node.AllocateContainer(rmContainer);
                    // Update usage for this container
                    IncreaseUsedResources(rmContainer);
                }
            }
            return(assignedContainers);
        }
Esempio n. 9
0
        public virtual void TestDelaySchedulingForContinuousScheduling()
        {
            FSLeafQueue queue = scheduler.GetQueueManager().GetLeafQueue("queue", true);
            Priority    prio  = Org.Mockito.Mockito.Mock <Priority>();

            Org.Mockito.Mockito.When(prio.GetPriority()).ThenReturn(1);
            TestFSAppAttempt.MockClock clock = new TestFSAppAttempt.MockClock(this);
            scheduler.SetClock(clock);
            long nodeLocalityDelayMs = 5 * 1000L;
            // 5 seconds
            long rackLocalityDelayMs = 6 * 1000L;
            // 6 seconds
            RMContext            rmContext            = resourceManager.GetRMContext();
            ApplicationAttemptId applicationAttemptId = CreateAppAttemptId(1, 1);
            FSAppAttempt         schedulerApp         = new FSAppAttempt(scheduler, applicationAttemptId, "user1"
                                                                         , queue, null, rmContext);

            // Default level should be node-local
            NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevelByTime
                                                (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime()));
            // after 4 seconds should remain node local
            clock.Tick(4);
            NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevelByTime
                                                (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime()));
            // after 6 seconds should switch to rack local
            clock.Tick(2);
            NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevelByTime
                                                (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime()));
            // manually set back to node local
            schedulerApp.ResetAllowedLocalityLevel(prio, NodeType.NodeLocal);
            schedulerApp.ResetSchedulingOpportunities(prio, clock.GetTime());
            NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevelByTime
                                                (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime()));
            // Now escalate again to rack-local, then to off-switch
            clock.Tick(6);
            NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevelByTime
                                                (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime()));
            clock.Tick(7);
            NUnit.Framework.Assert.AreEqual(NodeType.OffSwitch, schedulerApp.GetAllowedLocalityLevelByTime
                                                (prio, nodeLocalityDelayMs, rackLocalityDelayMs, clock.GetTime()));
        }
Esempio n. 10
0
        private int AssignContainersOnNode(FiCaSchedulerNode node, FiCaSchedulerApp application
                                           , Priority priority)
        {
            // Data-local
            int nodeLocalContainers = AssignNodeLocalContainers(node, application, priority);
            // Rack-local
            int rackLocalContainers = AssignRackLocalContainers(node, application, priority);
            // Off-switch
            int offSwitchContainers = AssignOffSwitchContainers(node, application, priority);

            Log.Debug("assignContainersOnNode:" + " node=" + node.GetRMNode().GetNodeAddress(
                          ) + " application=" + application.GetApplicationId().GetId() + " priority=" + priority
                      .GetPriority() + " #assigned=" + (nodeLocalContainers + rackLocalContainers + offSwitchContainers
                                                        ));
            return(nodeLocalContainers + rackLocalContainers + offSwitchContainers);
        }
Esempio n. 11
0
        private void DecResourceRequest(Priority priority, string resourceName, Resource
                                        capability, T req)
        {
            IDictionary <string, SortedDictionary <Resource, AMRMClientImpl.ResourceRequestInfo
                                                   > > remoteRequests = this.remoteRequestsTable[priority];

            if (remoteRequests == null)
            {
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Not decrementing resource as priority " + priority + " is not present in request table"
                              );
                }
                return;
            }
            IDictionary <Resource, AMRMClientImpl.ResourceRequestInfo> reqMap = remoteRequests
                                                                                [resourceName];

            if (reqMap == null)
            {
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Not decrementing resource as " + resourceName + " is not present in request table"
                              );
                }
                return;
            }
            AMRMClientImpl.ResourceRequestInfo resourceRequestInfo = reqMap[capability];
            if (Log.IsDebugEnabled())
            {
                Log.Debug("BEFORE decResourceRequest:" + " applicationId=" + " priority=" + priority
                          .GetPriority() + " resourceName=" + resourceName + " numContainers=" + resourceRequestInfo
                          .remoteRequest.GetNumContainers() + " #asks=" + ask.Count);
            }
            resourceRequestInfo.remoteRequest.SetNumContainers(resourceRequestInfo.remoteRequest
                                                               .GetNumContainers() - 1);
            resourceRequestInfo.containerRequests.Remove(req);
            if (resourceRequestInfo.remoteRequest.GetNumContainers() < 0)
            {
                // guard against spurious removals
                resourceRequestInfo.remoteRequest.SetNumContainers(0);
            }
            // send the ResourceRequest to RM even if is 0 because it needs to override
            // a previously sent value. If ResourceRequest was not sent previously then
            // sending 0 aught to be a no-op on RM
            AddResourceRequestToAsk(resourceRequestInfo.remoteRequest);
            // delete entries from map if no longer needed
            if (resourceRequestInfo.remoteRequest.GetNumContainers() == 0)
            {
                Sharpen.Collections.Remove(reqMap, capability);
                if (reqMap.Count == 0)
                {
                    Sharpen.Collections.Remove(remoteRequests, resourceName);
                }
                if (remoteRequests.Count == 0)
                {
                    Sharpen.Collections.Remove(remoteRequestsTable, priority);
                }
            }
            if (Log.IsDebugEnabled())
            {
                Log.Info("AFTER decResourceRequest:" + " applicationId=" + " priority=" + priority
                         .GetPriority() + " resourceName=" + resourceName + " numContainers=" + resourceRequestInfo
                         .remoteRequest.GetNumContainers() + " #asks=" + ask.Count);
            }
        }