Ejemplo n.º 1
0
        public OrleansTaskScheduler(
            IOptions <SchedulingOptions> options,
            ExecutorService executorService,
            ILoggerFactory loggerFactory,
            SchedulerStatisticsGroup schedulerStatistics,
            IOptions <StatisticsOptions> statisticsOptions)
        {
            this.loggerFactory       = loggerFactory;
            this.schedulerStatistics = schedulerStatistics;
            this.statisticsOptions   = statisticsOptions;
            this.logger             = loggerFactory.CreateLogger <OrleansTaskScheduler>();
            cancellationTokenSource = new CancellationTokenSource();
            WorkItemGroup.ActivationSchedulingQuantum = options.Value.ActivationSchedulingQuantum;
            applicationTurnsStopped       = false;
            TurnWarningLengthThreshold    = options.Value.TurnWarningLengthThreshold;
            this.MaxPendingItemsSoftLimit = options.Value.MaxPendingWorkItemsSoftLimit;
            this.MaxPendingItemsHardLimit = options.Value.MaxPendingWorkItemsHardLimit;
            workgroupDirectory            = new ConcurrentDictionary <ISchedulingContext, WorkItemGroup>();

            const int maxSystemThreads = 2;
            var       maxActiveThreads = options.Value.MaxActiveThreads;

            maximumConcurrencyLevel = maxActiveThreads + maxSystemThreads;

            OrleansSchedulerAsynchAgent CreateSchedulerAsynchAgent(string agentName, bool drainAfterCancel, int degreeOfParallelism)
            {
                return(new OrleansSchedulerAsynchAgent(
                           agentName,
                           executorService,
                           degreeOfParallelism,
                           options.Value.DelayWarningThreshold,
                           options.Value.TurnWarningLengthThreshold,
                           this,
                           drainAfterCancel,
                           loggerFactory));
            }

            mainAgent   = CreateSchedulerAsynchAgent("Scheduler.LevelOne.MainQueue", false, maxActiveThreads);
            systemAgent = CreateSchedulerAsynchAgent("Scheduler.LevelOne.SystemQueue", true, maxSystemThreads);

            this.taskWorkItemLogger = loggerFactory.CreateLogger <TaskWorkItem>();
            logger.Info("Starting OrleansTaskScheduler with {0} Max Active application Threads and 2 system thread.", maxActiveThreads);
            IntValueStatistic.FindOrCreate(StatisticNames.SCHEDULER_WORKITEMGROUP_COUNT, () => WorkItemGroupCount);
            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_QUEUE_SIZE_INSTANTANEOUS_PER_QUEUE, "Scheduler.LevelOne"), () => RunQueueLength);

            if (!schedulerStatistics.CollectShedulerQueuesStats)
            {
                return;
            }

            FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_QUEUE_SIZE_AVERAGE_PER_QUEUE, "Scheduler.LevelTwo.Average"), () => AverageRunQueueLengthLevelTwo);
            FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_ENQUEUED_PER_QUEUE, "Scheduler.LevelTwo.Average"), () => AverageEnqueuedLevelTwo);
            FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_AVERAGE_ARRIVAL_RATE_PER_QUEUE, "Scheduler.LevelTwo.Average"), () => AverageArrivalRateLevelTwo);
            FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_QUEUE_SIZE_AVERAGE_PER_QUEUE, "Scheduler.LevelTwo.Sum"), () => SumRunQueueLengthLevelTwo);
            FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_ENQUEUED_PER_QUEUE, "Scheduler.LevelTwo.Sum"), () => SumEnqueuedLevelTwo);
            FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_AVERAGE_ARRIVAL_RATE_PER_QUEUE, "Scheduler.LevelTwo.Sum"), () => SumArrivalRateLevelTwo);
        }
 public SchedulerStatisticsTracker(OrleansSchedulerAsynchAgent agent)
 {
     this.agent = agent;
 }