public void EnsureThreadPoolInstanceIsTheOneRegisteredWithMetricsPublisherAndThreadPoolCache() { HystrixPlugins.RegisterMetricsPublisher(new MyHystrixMetricsPublisher()); IHystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKeyDefault.AsKey("threadPoolFactoryConcurrencyTest"); IHystrixThreadPool poolOne = new HystrixThreadPoolDefault( threadPoolKey, HystrixThreadPoolOptionsTest.GetUnitTestPropertiesBuilder()); IHystrixThreadPool poolTwo = new HystrixThreadPoolDefault( threadPoolKey, HystrixThreadPoolOptionsTest.GetUnitTestPropertiesBuilder()); Assert.Equal(poolOne.GetScheduler(), poolTwo.GetScheduler()); // Now that we get the threadPool from the metrics object, this will always be equal HystrixMetricsPublisherThreadPoolContainer hystrixMetricsPublisherThreadPool = (HystrixMetricsPublisherThreadPoolContainer)HystrixMetricsPublisherFactory .CreateOrRetrievePublisherForThreadPool(threadPoolKey, null, null); IHystrixTaskScheduler threadPoolExecutor = hystrixMetricsPublisherThreadPool.HystrixThreadPoolMetrics.TaskScheduler; // assert that both HystrixThreadPools share the same ThreadPoolExecutor as the one in HystrixMetricsPublisherThreadPool Assert.True(threadPoolExecutor.Equals(poolOne.GetScheduler()) && threadPoolExecutor.Equals(poolTwo.GetScheduler())); Assert.False(threadPoolExecutor.IsShutdown); // Now the HystrixThreadPool ALWAYS has the same reference to the ThreadPoolExecutor so that it no longer matters which // wins to be inserted into the HystrixThreadPool.Factory.threadPools cache. poolOne.Dispose(); poolTwo.Dispose(); }
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 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); }
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 static HystrixThreadPoolMetrics GetInstance(IHystrixThreadPoolKey key, IHystrixTaskScheduler taskScheduler, IHystrixThreadPoolOptions properties) { return(Metrics.GetOrAddEx(key.Name, (k) => new HystrixThreadPoolMetrics(key, taskScheduler, properties))); }