Beispiel #1
0
 internal WorkerPool(OrleansTaskScheduler sched, ICorePerformanceMetrics performanceMetrics, int maxActiveThreads, bool enableWorkerThreadInjection)
 {
     scheduler                   = sched;
     MaxActiveThreads            = maxActiveThreads;
     EnableWorkerThreadInjection = enableWorkerThreadInjection;
     MaxWorkQueueWait            = TimeSpan.FromMilliseconds(50);
     this.performanceMetrics     = performanceMetrics;
     if (EnableWorkerThreadInjection)
     {
         threadLimitingSemaphore = new Semaphore(maxActiveThreads, maxActiveThreads);
     }
     pool = new HashSet <WorkerPoolThread>();
     createThreadCount = 0;
     lockable          = new object();
     for (createThreadCount = 0; createThreadCount < MaxActiveThreads; createThreadCount++)
     {
         var t = new WorkerPoolThread(this, scheduler, performanceMetrics, createThreadCount);
         pool.Add(t);
     }
     createThreadCount++;
     systemThread       = new WorkerPoolThread(this, scheduler, performanceMetrics, createThreadCount, true);
     running            = false;
     runningThreadCount = 0;
     longTurnTimer      = null;
 }
Beispiel #2
0
        private OrleansTaskScheduler(int maxActiveThreads, TimeSpan delayWarningThreshold, TimeSpan activationSchedulingQuantum,
                                     TimeSpan turnWarningLengthThreshold, bool injectMoreWorkerThreads, int maxPendingItemsSoftLimit, int maxPendingItemsHardLimit,
                                     ICorePerformanceMetrics performanceMetrics, ExecutorService executorService, ILoggerFactory loggerFactory)
        {
            this.logger           = loggerFactory.CreateLogger <OrleansTaskScheduler>();
            this.loggerFactory    = loggerFactory;
            DelayWarningThreshold = delayWarningThreshold;
            WorkItemGroup.ActivationSchedulingQuantum = activationSchedulingQuantum;
            TurnWarningLengthThreshold    = turnWarningLengthThreshold;
            applicationTurnsStopped       = false;
            this.MaxPendingItemsSoftLimit = maxPendingItemsSoftLimit;
            this.MaxPendingItemsHardLimit = maxPendingItemsHardLimit;
            workgroupDirectory            = new ConcurrentDictionary <ISchedulingContext, WorkItemGroup>();
            RunQueue = new WorkQueue();
            this.taskWorkItemLogger = loggerFactory.CreateLogger <TaskWorkItem>();
            logger.Info("Starting OrleansTaskScheduler with {0} Max Active application Threads and 1 system thread.", maxActiveThreads);
            Pool = new WorkerPool(this, performanceMetrics, executorService, loggerFactory, maxActiveThreads, injectMoreWorkerThreads);
            IntValueStatistic.FindOrCreate(StatisticNames.SCHEDULER_WORKITEMGROUP_COUNT, () => WorkItemGroupCount);
            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_QUEUE_SIZE_INSTANTANEOUS_PER_QUEUE, "Scheduler.LevelOne"), () => RunQueueLength);

            if (!StatisticsCollector.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);
        }
Beispiel #3
0
 private void AddCoreMetricsParams(ICorePerformanceMetrics coreMetrics)
 {
     Add(nameof(coreMetrics.CpuUsage), coreMetrics.CpuUsage);
     Add(nameof(coreMetrics.MemoryUsage), coreMetrics.MemoryUsage);
     Add(nameof(coreMetrics.SendQueueLength), coreMetrics.SendQueueLength);
     Add(nameof(coreMetrics.ReceiveQueueLength), coreMetrics.ReceiveQueueLength);
     Add(nameof(coreMetrics.SentMessages), coreMetrics.SentMessages);
     Add(nameof(coreMetrics.ReceivedMessages), coreMetrics.ReceivedMessages);
 }
Beispiel #4
0
 public static OrleansTaskScheduler CreateTestInstance(int maxActiveThreads, ICorePerformanceMetrics performanceMetrics)
 {
     return(new OrleansTaskScheduler(
                maxActiveThreads,
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(100),
                NodeConfiguration.ENABLE_WORKER_THREAD_INJECTION,
                LimitManager.GetDefaultLimit(LimitNames.LIMIT_MAX_PENDING_ITEMS),
                performanceMetrics));
 }
Beispiel #5
0
 public static OrleansTaskScheduler CreateTestInstance(int maxActiveThreads, ICorePerformanceMetrics performanceMetrics, ILoggerFactory loggerFactory)
 {
     return(new OrleansTaskScheduler(
                maxActiveThreads,
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(100),
                SchedulingOptions.DEFAULT_ENABLE_WORKER_THREAD_INJECTION,
                SchedulingOptions.DEFAULT_MAX_PENDING_ITEMS_SOFT_LIMIT,
                SchedulingOptions.DEFAULT_MAX_PENDING_ITEMS_HARD_LIMIT,
                performanceMetrics,
                new ExecutorService(),
                loggerFactory));
 }
Beispiel #6
0
 internal WorkerPoolThread(WorkerPool gtp, OrleansTaskScheduler sched, ICorePerformanceMetrics performanceMetrics, int threadNumber, bool system = false)
     : base((system ? "System." : "") + threadNumber)
 {
     pool      = gtp;
     scheduler = sched;
     this.performanceMetrics = performanceMetrics;
     ownsSemaphore           = false;
     IsSystem               = system;
     maxWorkQueueWait       = IsSystem ? Constants.INFINITE_TIMESPAN : gtp.MaxWorkQueueWait;
     OnFault                = FaultBehavior.IgnoreFault;
     currentWorkItemStarted = DateTime.UtcNow;
     currentTaskStarted     = DateTime.UtcNow;
     CurrentWorkItem        = null;
     if (StatisticsCollector.CollectTurnsStats)
     {
         WorkerThreadStatisticsNumber = SchedulerStatisticsGroup.RegisterWorkingThread(Name);
     }
 }
Beispiel #7
0
 public OrleansTaskScheduler(IOptions <SchedulingOptions> options, ICorePerformanceMetrics performanceMetrics, ExecutorService executorService, ILoggerFactory loggerFactory)
     : this(options.Value.MaxActiveThreads, options.Value.DelayWarningThreshold, options.Value.ActivationSchedulingQuantum,
            options.Value.TurnWarningLengthThreshold, options.Value.EnableWorkerThreadInjection, options.Value.MaxPendingWorkItemsSoftLimit,
            options.Value.MaxPendingWorkItemsHardLimit, performanceMetrics, executorService, loggerFactory)
 {
 }
 public OrleansTaskScheduler(NodeConfiguration config, ICorePerformanceMetrics performanceMetrics, ILoggerFactory loggerFactory)
     : this(config.MaxActiveThreads, config.DelayWarningThreshold, config.ActivationSchedulingQuantum,
            config.TurnWarningLengthThreshold, config.EnableWorkerThreadInjection, config.LimitManager.GetLimit(LimitNames.LIMIT_MAX_PENDING_ITEMS),
            performanceMetrics, loggerFactory)
 {
 }
Beispiel #9
0
        internal static OrleansTaskScheduler InitializeSchedulerForTesting(ISchedulingContext context, ICorePerformanceMetrics performanceMetrics, ILoggerFactory loggerFactory)
        {
            StatisticsCollector.StatisticsCollectionLevel = StatisticsLevel.Info;
            SchedulerStatisticsGroup.Init(loggerFactory);
            var scheduler = OrleansTaskScheduler.CreateTestInstance(4, performanceMetrics, loggerFactory);

            scheduler.Start();
            WorkItemGroup ignore = scheduler.RegisterWorkContext(context);

            return(scheduler);
        }