From d7413178d01c0b3989ec10edeb942120fa876c27 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Mon, 20 Apr 2015 13:21:13 -0700 Subject: [PATCH 1/2] Added multi-threaded test that also reads metrics uring command execution --- hystrix-core/build.gradle | 2 +- .../perf/MultiThreadedMetricsTest.java | 113 ++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java diff --git a/hystrix-core/build.gradle b/hystrix-core/build.gradle index 8be52e095..7af01c363 100644 --- a/hystrix-core/build.gradle +++ b/hystrix-core/build.gradle @@ -36,7 +36,7 @@ jar { jmh { fork = 1 - iterations = 5 + iterations = 25 threads = 8 warmup = '1s' warmupBatchSize = 1 diff --git a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java new file mode 100644 index 000000000..9978a177d --- /dev/null +++ b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java @@ -0,0 +1,113 @@ +package com.netflix.hystrix.perf; + +import com.netflix.hystrix.HystrixCommand; +import com.netflix.hystrix.HystrixCommandGroupKey; +import com.netflix.hystrix.HystrixCommandProperties; +import com.netflix.hystrix.HystrixThreadPoolProperties; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Group; +import org.openjdk.jmh.annotations.GroupThreads; +import org.openjdk.jmh.annotations.Level; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; + +import java.util.concurrent.TimeUnit; + +public class MultiThreadedMetricsTest { + @State(Scope.Thread) + public static class CommandState { + HystrixCommand command; + + @Param({"THREAD", "SEMAPHORE"}) + public HystrixCommandProperties.ExecutionIsolationStrategy isolationStrategy; + + + @Setup(Level.Invocation) + public void setUp() { + command = new HystrixCommand( + HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("PERF")) + .andCommandPropertiesDefaults( + HystrixCommandProperties.Setter() + .withExecutionIsolationStrategy(isolationStrategy) + .withRequestCacheEnabled(true) + .withRequestLogEnabled(true) + .withCircuitBreakerEnabled(true) + .withCircuitBreakerForceOpen(false) + ) + .andThreadPoolPropertiesDefaults( + HystrixThreadPoolProperties.Setter() + .withCoreSize(100) + ) + ) { + @Override + protected Integer run() throws Exception { + return 1; + } + + @Override + protected Integer getFallback() { + return 2; + } + }; + } + } + + @Benchmark + @Group("writeHeavy") + @GroupThreads(7) + @BenchmarkMode({Mode.Throughput}) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public Integer writeHeavyCommandExecution(CommandState state) { + return state.command.observe().toBlocking().first(); + } + + @Benchmark + @Group("writeHeavy") + @GroupThreads(1) + @BenchmarkMode({Mode.Throughput}) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public Integer writeHeavyReadMetrics(CommandState state) { + return state.command.getMetrics().getCurrentConcurrentExecutionCount(); + } + + @Benchmark + @Group("evenSplit") + @GroupThreads(4) + @BenchmarkMode({Mode.Throughput}) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public Integer evenSplitOfWritesAndReadsCommandExecution(CommandState state) { + return state.command.observe().toBlocking().first(); + } + + @Benchmark + @Group("evenSplit") + @GroupThreads(4) + @BenchmarkMode({Mode.Throughput}) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public Integer evenSplitOfWritesAndReadsReadMetrics(CommandState state) { + return state.command.getMetrics().getCurrentConcurrentExecutionCount(); + } + + @Benchmark + @Group("readHeavy") + @GroupThreads(1) + @BenchmarkMode({Mode.Throughput}) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public Integer readHeavyCommandExecution(CommandState state) { + return state.command.observe().toBlocking().first(); + } + + @Benchmark + @Group("readHeavy") + @GroupThreads(7) + @BenchmarkMode({Mode.Throughput}) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public Integer readHeavyReadMetrics(CommandState state) { + return state.command.getMetrics().getCurrentConcurrentExecutionCount(); + } +} From b5ca485c42797b5e3fcc0a0d02f7cdb9dac98305 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 21 Apr 2015 09:39:24 -0700 Subject: [PATCH 2/2] Upgrade to jmh 1.9 and profile gc as well --- hystrix-core/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hystrix-core/build.gradle b/hystrix-core/build.gradle index 7af01c363..9757929c3 100644 --- a/hystrix-core/build.gradle +++ b/hystrix-core/build.gradle @@ -37,6 +37,8 @@ jar { jmh { fork = 1 iterations = 25 + jmhVersion = '1.9' + profilers = ['gc'] threads = 8 warmup = '1s' warmupBatchSize = 1