Exemple #1
0
        /// <summary>
        /// stop the dispatchers prefetching.
        /// </summary>
        /// <param name="taskIds">the task ids identifying the dispatchers to stop</param>
        /// <param name="availableToShutdownTaskIds">true if resume the remaining dispatchers.</param>
        public void StopDispatchers(IEnumerable <string> availableToShutdownTaskIds, IEnumerable <string> tasksInInterest, bool resumeRemaining = true)
        {
            lock (this.lockThis)
            {
                Debug.Assert(availableToShutdownTaskIds != null);
                Debug.Assert(tasksInInterest == null || !availableToShutdownTaskIds.Except(tasksInInterest).Any(), "availableToShutdownTaskIds is not subset of tasksInInterest");

                // Get dispatchers available to stop.
                foreach (string taskId in availableToShutdownTaskIds)
                {
                    Dispatcher dispatcher;
                    if (this.dispatcherDic.TryGetValue(taskId, out dispatcher))
                    {
                        BrokerTracing.TraceInfo(
                            "[DispatcherManager].StopDispatchers Stop Dispatcher ID = {0}, CoreCount = {1}",
                            dispatcher.TaskId,
                            dispatcher.Info.CoreCount);

                        dispatcher.Stop();
                    }
                    else
                    {
                        BrokerTracing.TraceInfo(
                            "[DispatcherManager].StopDispatchers ID = {0}. Not Found.",
                            taskId);
                    }
                }

                if (resumeRemaining)
                {
                    HashSet <string> tasksInInterestSet = null;
                    if (tasksInInterest != null)
                    {
                        tasksInInterestSet = new HashSet <string>(tasksInInterest);
                    }

                    HashSet <string> shouldNotResumeDispatcherIds = new HashSet <string>(availableToShutdownTaskIds);

                    // resume the remaining dispatchers
                    foreach (var dispatcher in this.dispatcherDic.Values.Where(d => TaskInInterestUtil.IsTaskInInterest(tasksInInterestSet, d.TaskId) && !shouldNotResumeDispatcherIds.Contains(d.TaskId)))
                    {
                        if (!shouldNotResumeDispatcherIds.Contains(dispatcher.TaskId))
                        {
                            dispatcher.Resume();
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Get the current resource usage state of the dispatchers.
        /// </summary>
        /// <param name="averageCoresPerDispatcher">average cores per dispatcher</param>
        /// <param name="totalCores">total used cores count</param>
        /// <remarks>Consider calc when dispatchers are added\removed</remarks>
        public void GetCoreResourceUsageInformation(
            IEnumerable <string> tasksInInterest,
            out int averageCoresPerDispatcher,
            out int totalCores)
        {
            totalCores = 0;

            HashSet <string> tasksInInterestSet = null;

            if (tasksInInterest != null)
            {
                tasksInInterestSet = new HashSet <string>(tasksInInterest);
            }

            lock (this.lockThis)
            {
                var dispatcherInInterest        = this.dispatcherDic.Values.Where(d => TaskInInterestUtil.IsTaskInInterest(tasksInInterestSet, d.TaskId)).ToList();
                var blockedDispatcherInInterest = this.blockedDispatcherDic.Values.Where(i => TaskInInterestUtil.IsTaskInInterest(tasksInInterestSet, i.UniqueId)).ToList();

                int dispatcherCount = dispatcherInInterest.Count + blockedDispatcherInInterest.Count;
                if (dispatcherCount == 0)
                {
                    averageCoresPerDispatcher = 0;
                    totalCores = 0;
                    return;
                }

                foreach (Dispatcher dispatcher in dispatcherInInterest)
                {
                    totalCores += dispatcher.Info.CoreCount;
                }

                foreach (DispatcherInfo dispatcherInfo in blockedDispatcherInInterest)
                {
                    totalCores += dispatcherInfo.CoreCount;
                }

                averageCoresPerDispatcher = (int)(totalCores / dispatcherCount);
            }
        }