Example #1
0
        private static DedicatedThreadPoolSettings ConfigureSettings(Config config)
        {
            var dtp = config.GetConfig("dedicated-thread-pool");
            var fje = config.GetConfig("fork-join-executor");

            if ((dtp == null || dtp.IsEmpty) && (fje == null || fje.IsEmpty))
            {
                throw new ConfigurationException(
                          $"must define section 'dedicated-thread-pool' OR 'fork-join-executor' for fork-join-executor {config.GetString("id", "unknown")}");
            }

            if (dtp != null && !dtp.IsEmpty)
            {
                var settings = new DedicatedThreadPoolSettings(dtp.GetInt("thread-count"),
                                                               DedicatedThreadPoolConfigHelpers.ConfigureThreadType(dtp.GetString("threadtype",
                                                                                                                                  ThreadType.Background.ToString())),
                                                               config.GetString("id"),
                                                               DedicatedThreadPoolConfigHelpers.GetSafeDeadlockTimeout(dtp));
                return(settings);
            }
            else
            {
                var settings = new DedicatedThreadPoolSettings(ThreadPoolConfig.ScaledPoolSize(fje.GetInt("parallelism-min"), 1.0, fje.GetInt("parallelism-max")),
                                                               name: config.GetString("id"));
                return(settings);
            }
        }
Example #2
0
        public ChannelExecutorConfigurator(Config config, IDispatcherPrerequisites prerequisites) : base(config, prerequisites)
        {
            var fje = config.GetConfig("fork-join-executor");

            MaxParallelism = ThreadPoolConfig.ScaledPoolSize(
                fje.GetInt("parallelism-min"),
                fje.GetDouble("parallelism-factor", 1.0D),         // the scalar-based factor to scale the threadpool size to
                fje.GetInt("parallelism-max"));
        }
Example #3
0
        public ChannelTaskScheduler(ExtendedActorSystem system)
        {
            //config channel-scheduler
            var config = system.Settings.Config.GetConfig("akka.channel-scheduler");

            _maximumConcurrencyLevel = ThreadPoolConfig.ScaledPoolSize(
                config.GetInt("parallelism-min"),
                config.GetDouble("parallelism-factor", 1.0D),         // the scalar-based factor to scale the threadpool size to
                config.GetInt("parallelism-max"));
            _maximumConcurrencyLevel = Math.Max(_maximumConcurrencyLevel, 1);
            _maxWork = Math.Max(config.GetInt("work-max", _maxWork), 3); //min 3 normal work in work-loop

            _workInterval = config.GetInt("work-interval", _workInterval);
            _workStep     = config.GetInt("work-step", _workStep);

            //create task schedulers
            var channelOptions = new UnboundedChannelOptions()
            {
                AllowSynchronousContinuations = true,
                SingleReader = _maximumConcurrencyLevel == 1,
                SingleWriter = false
            };

            _highScheduler   = new PriorityTaskScheduler(Channel.CreateUnbounded <Task>(channelOptions), TaskSchedulerPriority.AboveNormal);
            _normalScheduler = new PriorityTaskScheduler(Channel.CreateUnbounded <Task>(channelOptions), TaskSchedulerPriority.Normal);
            _lowScheduler    = new PriorityTaskScheduler(Channel.CreateUnbounded <Task>(channelOptions), TaskSchedulerPriority.Low);
            _idleScheduler   = new PriorityTaskScheduler(Channel.CreateUnbounded <Task>(channelOptions), TaskSchedulerPriority.Idle);

            //prefill coworker array
            _coworkers = new Task[_maximumConcurrencyLevel - 1];
            for (var i = 0; i < _coworkers.Length; i++)
            {
                _coworkers[i] = Task.CompletedTask;
            }

            //init paused timer
            _timer = new Timer(ScheduleCoWorkers, "timer", Timeout.Infinite, Timeout.Infinite);

            //start main worker
            _controlTask = Task.Factory.StartNew(ControlAsync, _cts.Token,
                                                 TaskCreationOptions.DenyChildAttach | TaskCreationOptions.LongRunning,
                                                 TaskScheduler.Default).Unwrap();
        }