public HystrixTaskScheduler(IHystrixThreadPoolOptions options)
        {
            if (options.MaximumSize < 1)
            {
                throw new ArgumentOutOfRangeException("maximumPoolSize");
            }

            if (options.CoreSize < 0)
            {
                throw new ArgumentOutOfRangeException("corePoolSize");
            }


            this.allowMaxToDivergeFromCore = options.AllowMaximumSizeToDivergeFromCoreSize;
            this.corePoolSize                = options.CoreSize;
            this.maximumPoolSize             = options.MaximumSize;
            this.keepAliveTime               = TimeSpan.FromMinutes(options.KeepAliveTimeMinutes);
            this.queueSize                   = options.MaxQueueSize;
            this.queueSizeRejectionThreshold = options.QueueSizeRejectionThreshold;

            int workThreads = 0;
            int compThreads = 0;

            System.Threading.ThreadPool.GetMinThreads(out workThreads, out compThreads);

            System.Threading.ThreadPool.SetMinThreads(Math.Max(workThreads, DEFAULT_MIN_WORKTHREADS), compThreads);
            ;
        }
        private HystrixThreadPoolMetrics(IHystrixThreadPoolKey threadPoolKey, IHystrixTaskScheduler threadPool, IHystrixThreadPoolOptions properties) : base(null)
        {
            this.threadPoolKey = threadPoolKey;
            this.threadPool    = threadPool;
            this.properties    = properties;

            rollingCounterStream    = RollingThreadPoolEventCounterStream.GetInstance(threadPoolKey, properties);
            cumulativeCounterStream = CumulativeThreadPoolEventCounterStream.GetInstance(threadPoolKey, properties);
            rollingThreadPoolMaxConcurrencyStream = RollingThreadPoolMaxConcurrencyStream.GetInstance(threadPoolKey, properties);
        }
 public virtual HystrixTaskScheduler GetTaskScheduler(IHystrixThreadPoolOptions options)
 {
     if (options.MaxQueueSize < 0)
     {
         return(new HystrixSyncTaskScheduler(options));
     }
     else
     {
         return(new HystrixQueuedTaskScheduler(options));
     }
 }
        public HystrixThreadPoolDefault(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions propertiesDefaults)
        {
            _properties = HystrixOptionsFactory.GetThreadPoolOptions(threadPoolKey, propertiesDefaults);
            _properties = propertiesDefaults ?? new HystrixThreadPoolOptions(threadPoolKey);
            var concurrencyStrategy = HystrixPlugins.ConcurrencyStrategy;

            _queueSize     = _properties.MaxQueueSize;
            _metrics       = HystrixThreadPoolMetrics.GetInstance(threadPoolKey, concurrencyStrategy.GetTaskScheduler(_properties), _properties);
            _taskScheduler = _metrics.TaskScheduler;

            /* strategy: HystrixMetricsPublisherThreadPool */
            HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForThreadPool(threadPoolKey, _metrics, _properties);
        }
Beispiel #5
0
        public HystrixThreadPoolDefault(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions propertiesDefaults)
        {
            this.properties = HystrixOptionsFactory.GetThreadPoolOptions(threadPoolKey, propertiesDefaults);
            this.properties = propertiesDefaults ?? new HystrixThreadPoolOptions(threadPoolKey);
            HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.ConcurrencyStrategy;

            this.queueSize     = properties.MaxQueueSize;
            this.metrics       = HystrixThreadPoolMetrics.GetInstance(threadPoolKey, concurrencyStrategy.GetTaskScheduler(properties), properties);
            this.taskScheduler = this.metrics.TaskScheduler;

            /* strategy: HystrixMetricsPublisherThreadPool */
            HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForThreadPool(threadPoolKey, this.metrics, this.properties);
        }
 public HystrixThreadPoolOptions(IHystrixThreadPoolKey key, IHystrixThreadPoolOptions defaults = null, IHystrixDynamicOptions dynamic = null)
     : this(defaults, dynamic)
 {
     ThreadPoolKey = key;
     AllowMaximumSizeToDivergeFromCoreSize = GetBoolean(HYSTRIX_THREADPOOL_PREFIX, key.Name, "allowMaximumSizeToDivergeFromCoreSize", Default_AllowMaximumSizeToDivergeFromCoreSize, defaults?.AllowMaximumSizeToDivergeFromCoreSize);
     CoreSize                    = GetInteger(HYSTRIX_THREADPOOL_PREFIX, key.Name, "coreSize", Default_CoreSize, defaults?.CoreSize);
     MaximumSize                 = GetInteger(HYSTRIX_THREADPOOL_PREFIX, key.Name, "maximumSize", Default_MaximumSize, defaults?.MaximumSize);
     KeepAliveTimeMinutes        = GetInteger(HYSTRIX_THREADPOOL_PREFIX, key.Name, "keepAliveTimeMinutes", Default_KeepAliveTimeMinutes, defaults?.KeepAliveTimeMinutes);
     MaxQueueSize                = GetInteger(HYSTRIX_THREADPOOL_PREFIX, key.Name, "maxQueueSize", Default_MaxQueueSize, defaults?.MaxQueueSize);
     QueueSizeRejectionThreshold = GetInteger(HYSTRIX_THREADPOOL_PREFIX, key.Name, "queueSizeRejectionThreshold", Default_QueueSizeRejectionThreshold, defaults?.QueueSizeRejectionThreshold);
     MetricsRollingStatisticalWindowInMilliseconds = GetInteger(HYSTRIX_THREADPOOL_PREFIX, key.Name, "metrics.rollingStats.timeInMilliseconds", Default_ThreadPoolRollingNumberStatisticalWindow, defaults?.MetricsRollingStatisticalWindowInMilliseconds);
     MetricsRollingStatisticalWindowBuckets        = GetInteger(HYSTRIX_THREADPOOL_PREFIX, key.Name, "metrics.rollingPercentile.numBuckets", Default_ThreadPoolRollingNumberStatisticalWindowBuckets, defaults?.MetricsRollingStatisticalWindowBuckets);
 }
        internal HystrixThreadPoolOptions(IHystrixThreadPoolOptions defaults = null, IHystrixDynamicOptions dynamic = null)
            : base(dynamic)
        {
            this.defaults = defaults;
            ThreadPoolKey = null;

            AllowMaximumSizeToDivergeFromCoreSize = Default_AllowMaximumSizeToDivergeFromCoreSize;
            CoreSize                    = Default_CoreSize;
            MaximumSize                 = Default_MaximumSize;
            KeepAliveTimeMinutes        = Default_KeepAliveTimeMinutes;
            MaxQueueSize                = Default_MaxQueueSize;
            QueueSizeRejectionThreshold = Default_QueueSizeRejectionThreshold;
            MetricsRollingStatisticalWindowInMilliseconds = Default_ThreadPoolRollingNumberStatisticalWindow;
            MetricsRollingStatisticalWindowBuckets        = Default_ThreadPoolRollingNumberStatisticalWindowBuckets;
        }
        public HystrixQueuedTaskScheduler(IHystrixThreadPoolOptions options) :
            base(options)
        {
            if (options.MaxQueueSize < 0)
            {
                throw new ArgumentOutOfRangeException("MaxQueueSize");
            }

            if (options.QueueSizeRejectionThreshold < 0)
            {
                throw new ArgumentOutOfRangeException("queueSizeRejectionThreshold");
            }

            this.workQueue = new BlockingCollection <Task>(queueSize);

            StartThreadPoolWorker();
            runningThreads = 1;
        }
        public HystrixCommand(IHystrixCommandGroupKey group, IHystrixCommandKey key, IHystrixThreadPoolKey threadPoolKey, IHystrixCircuitBreaker circuitBreaker, IHystrixThreadPool threadPool,
                              IHystrixCommandOptions commandOptionsDefaults, IHystrixThreadPoolOptions threadPoolOptionsDefaults, HystrixCommandMetrics metrics, SemaphoreSlim fallbackSemaphore, SemaphoreSlim executionSemaphore,
                              HystrixOptionsStrategy optionsStrategy, HystrixCommandExecutionHook executionHook, Action run, Action fallback, ILogger logger = null) :
            base(group, key, threadPoolKey, circuitBreaker, threadPool, commandOptionsDefaults, threadPoolOptionsDefaults, metrics, fallbackSemaphore, executionSemaphore, optionsStrategy, executionHook, null, null, logger)
        {
            if (run == null)
            {
                _run = () => Run();
            }
            else
            {
                _run = run;
            }

            if (fallback == null)
            {
                _fallback = () => RunFallback();
            }
            else
            {
                _fallback = fallback;
            }
        }
        public HystrixTaskScheduler(IHystrixThreadPoolOptions options)
        {
            if (options.MaximumSize < 1)
            {
                throw new ArgumentOutOfRangeException("maximumPoolSize");
            }

            if (options.CoreSize < 0)
            {
                throw new ArgumentOutOfRangeException("corePoolSize");
            }


            this.allowMaxToDivergeFromCore = options.AllowMaximumSizeToDivergeFromCoreSize;
            this.corePoolSize                = options.CoreSize;
            this.maximumPoolSize             = options.MaximumSize;
            this.keepAliveTime               = TimeSpan.FromMinutes(options.KeepAliveTimeMinutes);
            this.queueSize                   = options.MaxQueueSize;
            this.queueSizeRejectionThreshold = options.QueueSizeRejectionThreshold;
#if NET46
            System.Threading.ThreadPool.SetMinThreads(20, 10);
#endif
        }
 public HystrixMetricsPublisherThreadPoolDefault(IHystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolOptions properties)
 {
     // do nothing by default
 }
Beispiel #12
0
        internal static IHystrixThreadPool GetInstance(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions propertiesBuilder)
        {
            // get the key to use instead of using the object itself so that if people forget to implement equals/hashcode things will still work
            var key = threadPoolKey.Name;

            // if we get here this is the first time so we need to initialize
            return(ThreadPools.GetOrAddEx(key, (k) => new HystrixThreadPoolDefault(threadPoolKey, propertiesBuilder)));
        }
 public virtual string GetThreadPoolOptionsCacheKey(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions builder)
 {
     return(threadPoolKey.Name);
 }
 public virtual IHystrixThreadPoolOptions GetThreadPoolOptions(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions builder)
 {
     return(new HystrixThreadPoolOptions(threadPoolKey, builder));
 }
Beispiel #15
0
 public virtual IHystrixMetricsPublisherThreadPool GetMetricsPublisherForThreadPool(IHystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolOptions properties)
 {
     return(new HystrixMetricsPublisherThreadPoolDefault(threadPoolKey, metrics, properties));
 }
Beispiel #16
0
 public static IHystrixMetricsPublisherThreadPool CreateOrRetrievePublisherForThreadPool(IHystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolOptions properties)
 {
     return(SINGLETON.GetPublisherForThreadPool(threadPoolKey, metrics, properties));
 }
Beispiel #17
0
 public override string GetThreadPoolOptionsCacheKey(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions builder)
 {
     return(null);
 }
 public HystrixSyncTaskScheduler(IHystrixThreadPoolOptions options)
     : base(options)
 {
     SetupWorkQueues(corePoolSize);
 }
Beispiel #19
0
        public static RollingThreadPoolMaxConcurrencyStream GetInstance(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions properties)
        {
            int counterMetricWindow   = properties.MetricsRollingStatisticalWindowInMilliseconds;
            int numCounterBuckets     = properties.MetricsRollingStatisticalWindowBuckets;
            int counterBucketSizeInMs = counterMetricWindow / numCounterBuckets;

            return(GetInstance(threadPoolKey, numCounterBuckets, counterBucketSizeInMs));
        }
Beispiel #20
0
 internal IHystrixMetricsPublisherThreadPool GetPublisherForThreadPool(IHystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolOptions properties)
 {
     return(threadPoolPublishers.GetOrAddEx(threadPoolKey.Name, (k) =>
     {
         IHystrixMetricsPublisherThreadPool publisher = HystrixPlugins.MetricsPublisher.GetMetricsPublisherForThreadPool(threadPoolKey, metrics, properties);
         publisher.Initialize();
         return publisher;
     }));
 }
 public override IHystrixMetricsPublisherThreadPool GetMetricsPublisherForThreadPool(IHystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolOptions properties)
 {
     return(new HystrixMetricsPublisherThreadPoolContainer(metrics));
 }
Beispiel #22
0
 private static HystrixThreadPoolConfiguration SampleThreadPoolConfiguration(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions threadPoolProperties)
 {
     return(HystrixThreadPoolConfiguration.Sample(threadPoolKey, threadPoolProperties));
 }
Beispiel #23
0
 public static HystrixThreadPoolConfiguration Sample(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions threadPoolProperties)
 {
     return(new HystrixThreadPoolConfiguration(
                threadPoolKey,
                threadPoolProperties.CoreSize,
                threadPoolProperties.MaximumSize,
                threadPoolProperties.MaxQueueSize,
                threadPoolProperties.QueueSizeRejectionThreshold,
                threadPoolProperties.KeepAliveTimeMinutes,
                threadPoolProperties.AllowMaximumSizeToDivergeFromCoreSize,
                threadPoolProperties.MetricsRollingStatisticalWindowBuckets,
                threadPoolProperties.MetricsRollingStatisticalWindowInMilliseconds));
 }
Beispiel #24
0
        public override IHystrixThreadPoolOptions GetThreadPoolOptions(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions builder)
        {
            if (builder == null)
            {
                builder = HystrixThreadPoolOptionsTest.GetUnitTestPropertiesBuilder();
            }

            return(builder);
        }
 public static HystrixThreadPoolMetrics GetInstance(IHystrixThreadPoolKey key, IHystrixTaskScheduler taskScheduler, IHystrixThreadPoolOptions properties)
 {
     return(Metrics.GetOrAddEx(key.Name, (k) => new HystrixThreadPoolMetrics(key, taskScheduler, properties)));
 }
Beispiel #26
0
        public static IHystrixThreadPoolOptions GetThreadPoolOptions(IHystrixThreadPoolKey key, IHystrixThreadPoolOptions builder)
        {
            var hystrixPropertiesStrategy = HystrixPlugins.OptionsStrategy;
            var cacheKey = hystrixPropertiesStrategy.GetThreadPoolOptionsCacheKey(key, builder);

            if (cacheKey != null)
            {
                return(ThreadPoolProperties.GetOrAddEx(cacheKey, (k) => hystrixPropertiesStrategy.GetThreadPoolOptions(key, builder)));
            }
            else
            {
                // no cacheKey so we generate it with caching
                return(hystrixPropertiesStrategy.GetThreadPoolOptions(key, builder));
            }
        }
Beispiel #27
0
 public TestCommandBuilder SetThreadPoolPropertiesDefaults(IHystrixThreadPoolOptions threadPoolPropertiesDefaults)
 {
     this.ThreadPoolPropertiesDefaults = threadPoolPropertiesDefaults;
     return(this);
 }
Beispiel #28
0
            public override IHystrixMetricsPublisherThreadPool GetMetricsPublisherForThreadPool(IHystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolOptions properties)

            {
                return(new MyHystrixMetricsPublisherThreadPool(threadCounter));
            }
Beispiel #29
0
        public static CumulativeThreadPoolEventCounterStream GetInstance(IHystrixThreadPoolKey threadPoolKey, IHystrixThreadPoolOptions properties)
        {
            var counterMetricWindow   = properties.MetricsRollingStatisticalWindowInMilliseconds;
            var numCounterBuckets     = properties.MetricsRollingStatisticalWindowBuckets;
            var counterBucketSizeInMs = counterMetricWindow / numCounterBuckets;

            return(GetInstance(threadPoolKey, numCounterBuckets, counterBucketSizeInMs));
        }