From 16ea656be2f57dc934735f45fead82b0685259bd Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Sat, 30 Jan 2016 12:02:31 -0800 Subject: [PATCH] Renaming thread pool max concurrency stream, for consistency --- ...ystrixServoMetricsPublisherThreadPool.java | 4 +-- .../hystrix/HystrixThreadPoolMetrics.java | 8 +++--- .../RollingCommandMaxConcurrencyStream.java | 20 +++----------- ...ollingThreadPoolMaxConcurrencyStream.java} | 20 +++++++------- ...ngThreadPoolMaxConcurrencyStreamTest.java} | 26 +++++++++---------- 5 files changed, 32 insertions(+), 46 deletions(-) rename hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/{RollingThreadPoolConcurrencyStream.java => RollingThreadPoolMaxConcurrencyStream.java} (69%) rename hystrix-core/src/test/java/com/netflix/hystrix/metric/consumer/{RollingThreadPoolConcurrencyStreamTest.java => RollingThreadPoolMaxConcurrencyStreamTest.java} (94%) diff --git a/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherThreadPool.java b/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherThreadPool.java index ba7f121c7..9e03a6f6a 100644 --- a/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherThreadPool.java +++ b/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherThreadPool.java @@ -20,7 +20,7 @@ import com.netflix.hystrix.HystrixThreadPoolMetrics; import com.netflix.hystrix.HystrixThreadPoolProperties; import com.netflix.hystrix.metric.consumer.CumulativeThreadPoolEventCounterStream; -import com.netflix.hystrix.metric.consumer.RollingThreadPoolConcurrencyStream; +import com.netflix.hystrix.metric.consumer.RollingThreadPoolMaxConcurrencyStream; import com.netflix.hystrix.metric.consumer.RollingThreadPoolEventCounterStream; import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherThreadPool; import com.netflix.servo.DefaultMonitorRegistry; @@ -104,7 +104,7 @@ public void initialize() { DefaultMonitorRegistry.getInstance().register(commandMetricsMonitor); RollingThreadPoolEventCounterStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted(); CumulativeThreadPoolEventCounterStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted(); - RollingThreadPoolConcurrencyStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted(); + RollingThreadPoolMaxConcurrencyStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted(); } @Override diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolMetrics.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolMetrics.java index c42f00c7b..8b97657c8 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolMetrics.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolMetrics.java @@ -17,7 +17,7 @@ import com.netflix.hystrix.metric.HystrixCommandCompletion; import com.netflix.hystrix.metric.consumer.CumulativeThreadPoolEventCounterStream; -import com.netflix.hystrix.metric.consumer.RollingThreadPoolConcurrencyStream; +import com.netflix.hystrix.metric.consumer.RollingThreadPoolMaxConcurrencyStream; import com.netflix.hystrix.metric.consumer.RollingThreadPoolEventCounterStream; import com.netflix.hystrix.util.HystrixRollingNumberEvent; import org.slf4j.Logger; @@ -141,7 +141,7 @@ public long[] call(long[] cumulativeEvents, long[] bucketEventCounts) { private final RollingThreadPoolEventCounterStream rollingCounterStream; private final CumulativeThreadPoolEventCounterStream cumulativeCounterStream; - private final RollingThreadPoolConcurrencyStream rollingThreadPoolConcurrencyStream; + private final RollingThreadPoolMaxConcurrencyStream rollingThreadPoolMaxConcurrencyStream; private HystrixThreadPoolMetrics(HystrixThreadPoolKey threadPoolKey, ThreadPoolExecutor threadPool, HystrixThreadPoolProperties properties) { super(null); @@ -151,7 +151,7 @@ private HystrixThreadPoolMetrics(HystrixThreadPoolKey threadPoolKey, ThreadPoolE rollingCounterStream = RollingThreadPoolEventCounterStream.getInstance(threadPoolKey, properties); cumulativeCounterStream = CumulativeThreadPoolEventCounterStream.getInstance(threadPoolKey, properties); - rollingThreadPoolConcurrencyStream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, properties); + rollingThreadPoolMaxConcurrencyStream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, properties); } /** @@ -333,7 +333,7 @@ public void markThreadCompletion() { * @return rolling max active threads */ public long getRollingMaxActiveThreads() { - return rollingThreadPoolConcurrencyStream.getLatestRollingMax(); + return rollingThreadPoolMaxConcurrencyStream.getLatestRollingMax(); } /** diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/RollingCommandMaxConcurrencyStream.java b/hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/RollingCommandMaxConcurrencyStream.java index fa45a78f2..16ea3c4dc 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/RollingCommandMaxConcurrencyStream.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/RollingCommandMaxConcurrencyStream.java @@ -23,30 +23,16 @@ import java.util.concurrent.ConcurrentMap; /** - * Maintains a stream of concurrency distributions for a given Command. + * Maintains a stream of the maximum concurrency seen by this command. * - * There are 2 related streams that may be consumed: - * - * A) A rolling window of the maximum concurrency seen by this command. - * B) A histogram of sampled concurrency seen by this command. - * - * A) gets calculated using a rolling window of t1 milliseconds. This window has b buckets. + * This gets calculated using a rolling window of t1 milliseconds. This window has b buckets. * Therefore, a new rolling-max is produced every t2 (=t1/b) milliseconds * t1 = {@link HystrixCommandProperties#metricsRollingStatisticalWindowInMilliseconds()} * b = {@link HystrixCommandProperties#metricsRollingStatisticalWindowBuckets()} * * This value gets cached in this class. It may be queried using {@link #getLatestRollingMax()} + * This value is stable - there's no peeking into a bucket until it is emitted * - * B) gets calculated by sampling the actual concurrency at some rate higher than the bucket-rolling frequency. - * Each sample gets stored in a histogram. At the moment, there's no bucketing or windowing on this stream. - * To control the emission rate, the histogram is emitted on a bucket-roll. - * - * This value is not cached. You need to consume this stream directly if you want to use it. - * - * Both A) and B) are stable - there's no peeking into a bucket until it is emitted - * - * LARGE CAVEAT: - * This will change after 1.5.0-RC.1. This was an experiment that proved too costly. Rely on this at your own peril */ public class RollingCommandMaxConcurrencyStream extends RollingConcurrencyStream { diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolConcurrencyStream.java b/hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolMaxConcurrencyStream.java similarity index 69% rename from hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolConcurrencyStream.java rename to hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolMaxConcurrencyStream.java index 4f17b4085..a4e94fef3 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolConcurrencyStream.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolMaxConcurrencyStream.java @@ -34,11 +34,11 @@ * * This is a stable value - there's no peeking into a bucket until it is emitted */ -public class RollingThreadPoolConcurrencyStream extends RollingConcurrencyStream { +public class RollingThreadPoolMaxConcurrencyStream extends RollingConcurrencyStream { - private static final ConcurrentMap streams = new ConcurrentHashMap(); + private static final ConcurrentMap streams = new ConcurrentHashMap(); - public static RollingThreadPoolConcurrencyStream getInstance(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties properties) { + public static RollingThreadPoolMaxConcurrencyStream getInstance(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties properties) { final int counterMetricWindow = properties.metricsRollingStatisticalWindowInMilliseconds().get(); final int numCounterBuckets = properties.metricsRollingStatisticalWindowBuckets().get(); final int counterBucketSizeInMs = counterMetricWindow / numCounterBuckets; @@ -46,16 +46,16 @@ public static RollingThreadPoolConcurrencyStream getInstance(HystrixThreadPoolKe return getInstance(threadPoolKey, numCounterBuckets, counterBucketSizeInMs); } - public static RollingThreadPoolConcurrencyStream getInstance(HystrixThreadPoolKey threadPoolKey, int numBuckets, int bucketSizeInMs) { - RollingThreadPoolConcurrencyStream initialStream = streams.get(threadPoolKey.name()); + public static RollingThreadPoolMaxConcurrencyStream getInstance(HystrixThreadPoolKey threadPoolKey, int numBuckets, int bucketSizeInMs) { + RollingThreadPoolMaxConcurrencyStream initialStream = streams.get(threadPoolKey.name()); if (initialStream != null) { return initialStream; } else { - synchronized (RollingThreadPoolConcurrencyStream.class) { - RollingThreadPoolConcurrencyStream existingStream = streams.get(threadPoolKey.name()); + synchronized (RollingThreadPoolMaxConcurrencyStream.class) { + RollingThreadPoolMaxConcurrencyStream existingStream = streams.get(threadPoolKey.name()); if (existingStream == null) { - RollingThreadPoolConcurrencyStream newStream = - new RollingThreadPoolConcurrencyStream(threadPoolKey, numBuckets, bucketSizeInMs); + RollingThreadPoolMaxConcurrencyStream newStream = + new RollingThreadPoolMaxConcurrencyStream(threadPoolKey, numBuckets, bucketSizeInMs); streams.putIfAbsent(threadPoolKey.name(), newStream); return newStream; } else { @@ -69,7 +69,7 @@ public static void reset() { streams.clear(); } - public RollingThreadPoolConcurrencyStream(final HystrixThreadPoolKey threadPoolKey, final int numBuckets, final int bucketSizeInMs) { + public RollingThreadPoolMaxConcurrencyStream(final HystrixThreadPoolKey threadPoolKey, final int numBuckets, final int bucketSizeInMs) { super(HystrixThreadPoolStartStream.getInstance(threadPoolKey), numBuckets, bucketSizeInMs); } } diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolConcurrencyStreamTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolMaxConcurrencyStreamTest.java similarity index 94% rename from hystrix-core/src/test/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolConcurrencyStreamTest.java rename to hystrix-core/src/test/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolMaxConcurrencyStreamTest.java index 4307fe7c5..a3a35264b 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolConcurrencyStreamTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/metric/consumer/RollingThreadPoolMaxConcurrencyStreamTest.java @@ -38,8 +38,8 @@ import static org.junit.Assert.*; -public class RollingThreadPoolConcurrencyStreamTest extends CommandStreamTest { - RollingThreadPoolConcurrencyStream stream; +public class RollingThreadPoolMaxConcurrencyStreamTest extends CommandStreamTest { + RollingThreadPoolMaxConcurrencyStream stream; HystrixRequestContext context; ExecutorService threadPool; @@ -81,7 +81,7 @@ public void testEmptyStreamProducesZeros() { HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-A"); HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-A"); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-A"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1); @@ -102,7 +102,7 @@ public void testStartsAndEndsInSameBucketProduceValue() throws InterruptedExcept HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-B"); HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-B"); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-B"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1); @@ -124,7 +124,7 @@ public void testStartsAndEndsInSameBucketSemaphoreIsolated() throws InterruptedE HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-C"); HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-C"); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-C"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1); @@ -153,7 +153,7 @@ public void testOneCommandCarriesOverToNextBucket() throws InterruptedException HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-D"); HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-D"); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-D"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1); @@ -188,7 +188,7 @@ public void testMultipleCommandsCarryOverMultipleBuckets() throws InterruptedExc HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-E"); HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-E"); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-E"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1); @@ -229,7 +229,7 @@ public void testMultipleCommandsCarryOverMultipleBucketsForMultipleThreadPools() HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-X"); HystrixCommandKey keyX = HystrixCommandKey.Factory.asKey("RollingConcurrency-X"); HystrixCommandKey keyY = HystrixCommandKey.Factory.asKey("RollingConcurrency-Y"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1); @@ -267,7 +267,7 @@ public void testMultipleCommandsCarryOverMultipleBucketsAndThenAgeOut() throws I HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-F"); HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-F"); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-F"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1); @@ -295,7 +295,7 @@ public void testConcurrencyStreamProperlyFiltersOutResponseFromCache() throws In HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-G"); HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-G"); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-G"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1); @@ -325,7 +325,7 @@ public void testConcurrencyStreamProperlyFiltersOutShortCircuits() throws Interr HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-H"); HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-H"); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-H"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1); @@ -367,7 +367,7 @@ public void testConcurrencyStreamProperlyFiltersOutSemaphoreRejections() throws HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-I"); HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-I"); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-I"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1); @@ -422,7 +422,7 @@ public void testConcurrencyStreamProperlyFiltersOutThreadPoolRejections() throws HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ThreadPool-Concurrency-J"); HystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKey.Factory.asKey("ThreadPool-Concurrency-J"); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("RollingConcurrency-J"); - stream = RollingThreadPoolConcurrencyStream.getInstance(threadPoolKey, 10, 100); + stream = RollingThreadPoolMaxConcurrencyStream.getInstance(threadPoolKey, 10, 100); stream.startCachingStreamValuesIfUnstarted(); final CountDownLatch latch = new CountDownLatch(1);