/// <summary>
        /// Checks whether making the application runnable would exceed any
        /// maxRunningApps limits.
        /// </summary>
        public virtual bool CanAppBeRunnable(FSQueue queue, string user)
        {
            AllocationConfiguration allocConf = scheduler.GetAllocationConfiguration();
            int userNumRunnable = usersNumRunnableApps[user];

            if (userNumRunnable == null)
            {
                userNumRunnable = 0;
            }
            if (userNumRunnable >= allocConf.GetUserMaxApps(user))
            {
                return(false);
            }
            // Check queue and all parent queues
            while (queue != null)
            {
                int queueMaxApps = allocConf.GetQueueMaxApps(queue.GetName());
                if (queue.GetNumRunnableApps() >= queueMaxApps)
                {
                    return(false);
                }
                queue = queue.GetParent();
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Headroom depends on resources in the cluster, current usage of the
        /// queue, queue's fair-share and queue's max-resources.
        /// </summary>
        public override Org.Apache.Hadoop.Yarn.Api.Records.Resource GetHeadroom()
        {
            FSQueue          queue  = (FSQueue)this.queue;
            SchedulingPolicy policy = queue.GetPolicy();

            Org.Apache.Hadoop.Yarn.Api.Records.Resource queueFairShare  = queue.GetFairShare();
            Org.Apache.Hadoop.Yarn.Api.Records.Resource queueUsage      = queue.GetResourceUsage();
            Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = this.scheduler.GetClusterResource
                                                                              ();
            Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterUsage = this.scheduler.GetRootQueueMetrics
                                                                           ().GetAllocatedResources();
            Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterAvailableResources = Resources
                                                                                    .Subtract(clusterResource, clusterUsage);
            Org.Apache.Hadoop.Yarn.Api.Records.Resource queueMaxAvailableResources = Resources
                                                                                     .Subtract(queue.GetMaxShare(), queueUsage);
            Org.Apache.Hadoop.Yarn.Api.Records.Resource maxAvailableResource = Resources.ComponentwiseMin
                                                                                   (clusterAvailableResources, queueMaxAvailableResources);
            Org.Apache.Hadoop.Yarn.Api.Records.Resource headroom = policy.GetHeadroom(queueFairShare
                                                                                      , queueUsage, maxAvailableResource);
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Headroom calculation for " + this.GetName() + ":" + "Min(" + "(queueFairShare="
                          + queueFairShare + " - queueUsage=" + queueUsage + ")," + " maxAvailableResource="
                          + maxAvailableResource + "Headroom=" + headroom);
            }
            return(headroom);
        }
Esempio n. 3
0
 /// <summary>Remove the queue if it and its descendents are all empty.</summary>
 /// <param name="queue"/>
 /// <returns>true if removed, false otherwise</returns>
 private bool RemoveQueueIfEmpty(FSQueue queue)
 {
     if (IsEmpty(queue))
     {
         RemoveQueue(queue);
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
        /// <summary>Get a parent queue by name, creating it if the create param is true and is necessary.
        ///     </summary>
        /// <remarks>
        /// Get a parent queue by name, creating it if the create param is true and is necessary.
        /// If the queue is not or can not be a parent queue, i.e. it already exists as a
        /// leaf queue, or one of the parents in its name is already a leaf queue,
        /// null is returned.
        /// The root part of the name is optional, so a queue underneath the root
        /// named "queue1" could be referred to  as just "queue1", and a queue named
        /// "queue2" underneath a parent named "parent1" that is underneath the root
        /// could be referred to as just "parent1.queue2".
        /// </remarks>
        public virtual FSParentQueue GetParentQueue(string name, bool create)
        {
            FSQueue queue = GetQueue(name, create, FSQueueType.Parent);

            if (queue is FSLeafQueue)
            {
                return(null);
            }
            return((FSParentQueue)queue);
        }
Esempio n. 5
0
        /// <summary>
        /// Make way for the given queue if possible, by removing incompatible
        /// queues with no apps in them.
        /// </summary>
        /// <remarks>
        /// Make way for the given queue if possible, by removing incompatible
        /// queues with no apps in them. Incompatibility could be due to
        /// (1) queueToCreate being currently a parent but needs to change to leaf
        /// (2) queueToCreate being currently a leaf but needs to change to parent
        /// (3) an existing leaf queue in the ancestry of queueToCreate.
        /// We will never remove the root queue or the default queue in this way.
        /// </remarks>
        /// <returns>true if we can create queueToCreate or it already exists.</returns>
        private bool RemoveEmptyIncompatibleQueues(string queueToCreate, FSQueueType queueType
                                                   )
        {
            queueToCreate = EnsureRootPrefix(queueToCreate);
            // Ensure queueToCreate is not root and doesn't have the default queue in its
            // ancestry.
            if (queueToCreate.Equals(RootQueue) || queueToCreate.StartsWith(RootQueue + "." +
                                                                            YarnConfiguration.DefaultQueueName + "."))
            {
                return(false);
            }
            FSQueue queue = queues[queueToCreate];

            // Queue exists already.
            if (queue != null)
            {
                if (queue is FSLeafQueue)
                {
                    if (queueType == FSQueueType.Leaf)
                    {
                        // if queue is already a leaf then return true
                        return(true);
                    }
                    // remove incompatibility since queue is a leaf currently
                    // needs to change to a parent.
                    return(RemoveQueueIfEmpty(queue));
                }
                else
                {
                    if (queueType == FSQueueType.Parent)
                    {
                        return(true);
                    }
                    // If it's an existing parent queue and needs to change to leaf,
                    // remove it if it's empty.
                    return(RemoveQueueIfEmpty(queue));
                }
            }
            // Queue doesn't exist already. Check if the new queue would be created
            // under an existing leaf queue. If so, try removing that leaf queue.
            int sepIndex = queueToCreate.Length;

            sepIndex = queueToCreate.LastIndexOf('.', sepIndex - 1);
            while (sepIndex != -1)
            {
                string  prefixString = Sharpen.Runtime.Substring(queueToCreate, 0, sepIndex);
                FSQueue prefixQueue  = queues[prefixString];
                if (prefixQueue != null && prefixQueue is FSLeafQueue)
                {
                    return(RemoveQueueIfEmpty(prefixQueue));
                }
                sepIndex = queueToCreate.LastIndexOf('.', sepIndex - 1);
            }
            return(true);
        }
        /// <summary>
        /// Checks to see whether any other applications runnable now that the given
        /// application has been removed from the given queue.
        /// </summary>
        /// <remarks>
        /// Checks to see whether any other applications runnable now that the given
        /// application has been removed from the given queue.  And makes them so.
        /// Runs in O(n log(n)) where n is the number of queues that are under the
        /// highest queue that went from having no slack to having slack.
        /// </remarks>
        public virtual void UpdateRunnabilityOnAppRemoval(FSAppAttempt app, FSLeafQueue queue
                                                          )
        {
            AllocationConfiguration allocConf = scheduler.GetAllocationConfiguration();
            // childqueueX might have no pending apps itself, but if a queue higher up
            // in the hierarchy parentqueueY has a maxRunningApps set, an app completion
            // in childqueueX could allow an app in some other distant child of
            // parentqueueY to become runnable.
            // An app removal will only possibly allow another app to become runnable if
            // the queue was already at its max before the removal.
            // Thus we find the ancestor queue highest in the tree for which the app
            // that was at its maxRunningApps before the removal.
            FSQueue highestQueueWithAppsNowRunnable = (queue.GetNumRunnableApps() == allocConf
                                                       .GetQueueMaxApps(queue.GetName()) - 1) ? queue : null;
            FSParentQueue parent = queue.GetParent();

            while (parent != null)
            {
                if (parent.GetNumRunnableApps() == allocConf.GetQueueMaxApps(parent.GetName()) -
                    1)
                {
                    highestQueueWithAppsNowRunnable = parent;
                }
                parent = parent.GetParent();
            }
            IList <IList <FSAppAttempt> > appsNowMaybeRunnable = new AList <IList <FSAppAttempt> >(
                );

            // Compile lists of apps which may now be runnable
            // We gather lists instead of building a set of all non-runnable apps so
            // that this whole operation can be O(number of queues) instead of
            // O(number of apps)
            if (highestQueueWithAppsNowRunnable != null)
            {
                GatherPossiblyRunnableAppLists(highestQueueWithAppsNowRunnable, appsNowMaybeRunnable
                                               );
            }
            string user           = app.GetUser();
            int    userNumRunning = usersNumRunnableApps[user];

            if (userNumRunning == null)
            {
                userNumRunning = 0;
            }
            if (userNumRunning == allocConf.GetUserMaxApps(user) - 1)
            {
                IList <FSAppAttempt> userWaitingApps = usersNonRunnableApps.Get(user);
                if (userWaitingApps != null)
                {
                    appsNowMaybeRunnable.AddItem(userWaitingApps);
                }
            }
            UpdateAppsRunnability(appsNowMaybeRunnable, appsNowMaybeRunnable.Count);
        }
Esempio n. 7
0
 /// <summary>Remove a queue and all its descendents.</summary>
 private void RemoveQueue(FSQueue queue)
 {
     if (queue is FSLeafQueue)
     {
         leafQueues.Remove(queue);
     }
     else
     {
         IList <FSQueue> childQueues = queue.GetChildQueues();
         while (!childQueues.IsEmpty())
         {
             RemoveQueue(childQueues[0]);
         }
     }
     Sharpen.Collections.Remove(queues, queue.GetName());
     queue.GetParent().GetChildQueues().Remove(queue);
 }
Esempio n. 8
0
 /// <summary>
 /// Returns true if there are no applications, running or not, in the given
 /// queue or any of its descendents.
 /// </summary>
 protected internal virtual bool IsEmpty(FSQueue queue)
 {
     if (queue is FSLeafQueue)
     {
         FSLeafQueue leafQueue = (FSLeafQueue)queue;
         return(queue.GetNumRunnableApps() == 0 && leafQueue.GetNumNonRunnableApps() == 0);
     }
     else
     {
         foreach (FSQueue child in queue.GetChildQueues())
         {
             if (!IsEmpty(child))
             {
                 return(false);
             }
         }
         return(true);
     }
 }
Esempio n. 9
0
 private FSQueue GetQueue(string name, bool create, FSQueueType queueType)
 {
     name = EnsureRootPrefix(name);
     lock (queues)
     {
         FSQueue queue = queues[name];
         if (queue == null && create)
         {
             // if the queue doesn't exist,create it and return
             queue = CreateQueue(name, queueType);
             // Update steady fair share for all queues
             if (queue != null)
             {
                 rootQueue.RecomputeSteadyShares();
             }
         }
         return(queue);
     }
 }
 /// <summary>
 /// Traverses the queue hierarchy under the given queue to gather all lists
 /// of non-runnable applications.
 /// </summary>
 private void GatherPossiblyRunnableAppLists(FSQueue queue, IList <IList <FSAppAttempt
                                                                          > > appLists)
 {
     if (queue.GetNumRunnableApps() < scheduler.GetAllocationConfiguration().GetQueueMaxApps
             (queue.GetName()))
     {
         if (queue is FSLeafQueue)
         {
             appLists.AddItem(((FSLeafQueue)queue).GetCopyOfNonRunnableAppSchedulables());
         }
         else
         {
             foreach (FSQueue child in queue.GetChildQueues())
             {
                 GatherPossiblyRunnableAppLists(child, appLists);
             }
         }
     }
 }
Esempio n. 11
0
        public override RMContainer PreemptContainer()
        {
            RMContainer toBePreempted = null;
            // Find the childQueue which is most over fair share
            FSQueue candidateQueue             = null;
            IComparer <Schedulable> comparator = policy.GetComparator();

            foreach (FSQueue queue in childQueues)
            {
                if (candidateQueue == null || comparator.Compare(queue, candidateQueue) > 0)
                {
                    candidateQueue = queue;
                }
            }
            // Let the selected queue choose which of its container to preempt
            if (candidateQueue != null)
            {
                toBePreempted = candidateQueue.PreemptContainer();
            }
            return(toBePreempted);
        }
Esempio n. 12
0
 public virtual void AddChildQueue(FSQueue child)
 {
     childQueues.AddItem(child);
 }
Esempio n. 13
0
 protected internal override bool IsEmpty(FSQueue queue)
 {
     return(!this._enclosing.notEmptyQueues.Contains(queue));
 }