@Override public Number getValue() { return properties.actualMaximumSize(); } });
private void touchConfig() { final int dynamicCoreSize = properties.coreSize().get(); final int configuredMaximumSize = properties.maximumSize().get(); int dynamicMaximumSize = properties.actualMaximumSize(); final boolean allowSizesToDiverge = properties.getAllowMaximumSizeToDivergeFromCoreSize().get(); boolean maxTooLow = false; if (allowSizesToDiverge && configuredMaximumSize < dynamicCoreSize) { //if user sets maximum < core (or defaults get us there), we need to maintain invariant of core <= maximum dynamicMaximumSize = dynamicCoreSize; maxTooLow = true; } // In JDK 6, setCorePoolSize and setMaximumPoolSize will execute a lock operation. Avoid them if the pool size is not changed. if (threadPool.getCorePoolSize() != dynamicCoreSize || (allowSizesToDiverge && threadPool.getMaximumPoolSize() != dynamicMaximumSize)) { if (maxTooLow) { logger.error("Hystrix ThreadPool configuration for : " + metrics.getThreadPoolKey().name() + " is trying to set coreSize = " + dynamicCoreSize + " and maximumSize = " + configuredMaximumSize + ". Maximum size will be set to " + dynamicMaximumSize + ", the coreSize value, since it must be equal to or greater than the coreSize value"); } threadPool.setCorePoolSize(dynamicCoreSize); threadPool.setMaximumPoolSize(dynamicMaximumSize); } threadPool.setKeepAliveTime(properties.keepAliveTimeMinutes().get(), TimeUnit.MINUTES); }
@Test public void testSetNeitherCoreNorMaximumSizeWithDivergenceAllowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withAllowMaximumSizeToDivergeFromCoreSize(true)) { }; assertEquals(HystrixThreadPoolProperties.default_coreSize, properties.coreSize().get().intValue()); assertEquals(HystrixThreadPoolProperties.default_maximumSize, properties.maximumSize().get().intValue()); assertEquals(HystrixThreadPoolProperties.default_maximumSize, (int) properties.actualMaximumSize()); }
@Test public void testSetNeitherCoreNorMaximumSizeWithDivergenceDisallowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withAllowMaximumSizeToDivergeFromCoreSize(false)) { }; assertEquals(HystrixThreadPoolProperties.default_coreSize, properties.coreSize().get().intValue()); assertEquals(HystrixThreadPoolProperties.default_maximumSize, properties.maximumSize().get().intValue()); assertEquals(HystrixThreadPoolProperties.default_coreSize, (int) properties.actualMaximumSize()); }
@Test public void testSetCoreSizeOnlyWithDivergenceAllowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withCoreSize(14) .withAllowMaximumSizeToDivergeFromCoreSize(true)) { }; assertEquals(14, properties.coreSize().get().intValue()); assertEquals(HystrixThreadPoolProperties.default_maximumSize, properties.maximumSize().get().intValue()); assertEquals(14, (int) properties.actualMaximumSize()); }
@Test public void testSetMaximumSizeOnlyLowerThanDefaultCoreSizeWithDivergenceAllowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withMaximumSize(3) .withAllowMaximumSizeToDivergeFromCoreSize(true)) { }; assertEquals(HystrixThreadPoolProperties.default_coreSize, properties.coreSize().get().intValue()); assertEquals(3, properties.maximumSize().get().intValue()); assertEquals(HystrixThreadPoolProperties.default_coreSize, (int) properties.actualMaximumSize()); }
@Test public void testSetCoreSizeOnlyWithDivergenceDisallowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withCoreSize(14) .withAllowMaximumSizeToDivergeFromCoreSize(false)) { }; assertEquals(14, properties.coreSize().get().intValue()); assertEquals(HystrixThreadPoolProperties.default_maximumSize, properties.maximumSize().get().intValue()); assertEquals(14, (int) properties.actualMaximumSize()); }
@Test public void testSetMaximumSizeOnlyLowerThanDefaultCoreSizeWithDivergenceDisallowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withMaximumSize(3) .withAllowMaximumSizeToDivergeFromCoreSize(false)) { }; assertEquals(HystrixThreadPoolProperties.default_coreSize, properties.coreSize().get().intValue()); assertEquals(3, properties.maximumSize().get().intValue()); assertEquals(HystrixThreadPoolProperties.default_coreSize, (int) properties.actualMaximumSize()); }
@Test public void testSetMaximumSizeOnlyGreaterThanDefaultCoreSizeWithDivergenceDisallowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withMaximumSize(21) .withAllowMaximumSizeToDivergeFromCoreSize(false)) { }; assertEquals(HystrixThreadPoolProperties.default_coreSize, properties.coreSize().get().intValue()); assertEquals(21, properties.maximumSize().get().intValue()); assertEquals(HystrixThreadPoolProperties.default_coreSize, (int) properties.actualMaximumSize()); }
@Test public void testSetMaximumSizeOnlyGreaterThanDefaultCoreSizeWithDivergenceAllowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withMaximumSize(21) .withAllowMaximumSizeToDivergeFromCoreSize(true)) { }; assertEquals(HystrixThreadPoolProperties.default_coreSize, properties.coreSize().get().intValue()); assertEquals(21, properties.maximumSize().get().intValue()); assertEquals(21, (int) properties.actualMaximumSize()); }
@Test public void testSetCoreSizeEqualToMaximumSizeDivergenceAllowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withCoreSize(7) .withMaximumSize(7) .withAllowMaximumSizeToDivergeFromCoreSize(true)) { }; assertEquals(7, properties.coreSize().get().intValue()); assertEquals(7, properties.maximumSize().get().intValue()); assertEquals(7, (int) properties.actualMaximumSize()); }
@Test public void testSetCoreSizeLessThanMaximumSizeWithDivergenceDisallowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withCoreSize(2) .withMaximumSize(8) .withAllowMaximumSizeToDivergeFromCoreSize(false)) { }; assertEquals(2, properties.coreSize().get().intValue()); assertEquals(8, properties.maximumSize().get().intValue()); assertEquals(2, (int) properties.actualMaximumSize()); }
@Test public void testSetCoreSizeLessThanMaximumSizeWithDivergenceAllowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withCoreSize(2) .withMaximumSize(8) .withAllowMaximumSizeToDivergeFromCoreSize(true)) { }; assertEquals(2, properties.coreSize().get().intValue()); assertEquals(8, properties.maximumSize().get().intValue()); assertEquals(8, (int) properties.actualMaximumSize()); }
@Test public void testSetCoreSizeGreaterThanMaximumSizeWithDivergenceDisallowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withCoreSize(12) .withMaximumSize(8) .withAllowMaximumSizeToDivergeFromCoreSize(false)) { }; assertEquals(12, properties.coreSize().get().intValue()); assertEquals(8, properties.maximumSize().get().intValue()); assertEquals(12, (int) properties.actualMaximumSize()); }
@Test public void testSetCoreSizeEqualToMaximumSizeDivergenceDisallowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withCoreSize(7) .withMaximumSize(7) .withAllowMaximumSizeToDivergeFromCoreSize(false)) { }; assertEquals(7, properties.coreSize().get().intValue()); assertEquals(7, properties.maximumSize().get().intValue()); assertEquals(7, (int) properties.actualMaximumSize()); }
@Test public void testSetCoreSizeGreaterThanMaximumSizeWithDivergenceAllowed() { HystrixThreadPoolProperties properties = new HystrixThreadPoolProperties(TestThreadPoolKey.TEST, HystrixThreadPoolProperties.Setter() .withCoreSize(12) .withMaximumSize(8) .withAllowMaximumSizeToDivergeFromCoreSize(true)) { }; assertEquals(12, properties.coreSize().get().intValue()); assertEquals(8, properties.maximumSize().get().intValue()); assertEquals(12, (int) properties.actualMaximumSize()); } }
private HystrixThreadPoolConfiguration(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties threadPoolProperties) { this(threadPoolKey, threadPoolProperties.coreSize().get(), threadPoolProperties.maximumSize().get(), threadPoolProperties.actualMaximumSize(), threadPoolProperties.maxQueueSize().get(), threadPoolProperties.queueSizeRejectionThreshold().get(), threadPoolProperties.keepAliveTimeMinutes().get(), threadPoolProperties.getAllowMaximumSizeToDivergeFromCoreSize().get(), threadPoolProperties.metricsRollingStatisticalWindowBuckets().get(), threadPoolProperties.metricsRollingStatisticalWindowInMilliseconds().get()); }
@Override public Number value() { return properties.actualMaximumSize(); } });
@Override public Number getValue() { return properties.actualMaximumSize(); } });
private HystrixThreadPoolConfiguration(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties threadPoolProperties) { this(threadPoolKey, threadPoolProperties.coreSize().get(), threadPoolProperties.maximumSize().get(), threadPoolProperties.actualMaximumSize(), threadPoolProperties.maxQueueSize().get(), threadPoolProperties.queueSizeRejectionThreshold().get(), threadPoolProperties.keepAliveTimeMinutes().get(), threadPoolProperties.getAllowMaximumSizeToDivergeFromCoreSize().get(), threadPoolProperties.metricsRollingStatisticalWindowBuckets().get(), threadPoolProperties.metricsRollingStatisticalWindowInMilliseconds().get()); }