From c460a5e1d4d97872b137989253cc5cf8b70a4131 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Wed, 30 Dec 2015 06:27:44 -0800 Subject: [PATCH] Rename JMH tests for easier execution by regex --- ...tionAndConcurrentMetricsReadPerfTest.java} | 2 +- ...est.java => CommandExecutionPerfTest.java} | 47 +++-- .../CommandGroupKeyExecutionPerfTest.java | 197 ------------------ 3 files changed, 32 insertions(+), 214 deletions(-) rename hystrix-core/src/jmh/java/com/netflix/hystrix/perf/{MultiThreadedMetricsTest.java => CommandExecutionAndConcurrentMetricsReadPerfTest.java} (98%) rename hystrix-core/src/jmh/java/com/netflix/hystrix/perf/{CommandSetterExecutionPerfTest.java => CommandExecutionPerfTest.java} (78%) delete mode 100644 hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandGroupKeyExecutionPerfTest.java diff --git a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandExecutionAndConcurrentMetricsReadPerfTest.java similarity index 98% rename from hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java rename to hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandExecutionAndConcurrentMetricsReadPerfTest.java index b4cf55c79..30caf72f4 100644 --- a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/MultiThreadedMetricsTest.java +++ b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandExecutionAndConcurrentMetricsReadPerfTest.java @@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit; -public class MultiThreadedMetricsTest { +public class CommandExecutionAndConcurrentMetricsReadPerfTest { @State(Scope.Thread) public static class CommandState { HystrixCommand command; diff --git a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandSetterExecutionPerfTest.java b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandExecutionPerfTest.java similarity index 78% rename from hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandSetterExecutionPerfTest.java rename to hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandExecutionPerfTest.java index 96ad27292..a077e48ab 100644 --- a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandSetterExecutionPerfTest.java +++ b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandExecutionPerfTest.java @@ -31,6 +31,7 @@ import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.infra.Blackhole; import rx.Observable; import rx.schedulers.Schedulers; @@ -41,38 +42,52 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -public class CommandSetterExecutionPerfTest { +public class CommandExecutionPerfTest { + + static HystrixCommandProperties.Setter threadIsolatedCommandDefaults = HystrixCommandProperties.Setter() + .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD) + .withRequestCacheEnabled(true) + .withRequestLogEnabled(true) + .withCircuitBreakerEnabled(true) + .withCircuitBreakerForceOpen(false); + + static HystrixCommandProperties.Setter semaphoreIsolatedCommandDefaults = HystrixCommandProperties.Setter() + .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE) + .withRequestCacheEnabled(true) + .withRequestLogEnabled(true) + .withCircuitBreakerEnabled(true) + .withCircuitBreakerForceOpen(false); + + static HystrixThreadPoolProperties.Setter threadPoolDefaults = HystrixThreadPoolProperties.Setter() + .withCoreSize(100); + + private static HystrixCommandProperties.Setter getCommandSetter(HystrixCommandProperties.ExecutionIsolationStrategy isolationStrategy) { + switch (isolationStrategy) { + case THREAD: return threadIsolatedCommandDefaults; + default: return semaphoreIsolatedCommandDefaults; + } + } @State(Scope.Thread) public static class CommandState { HystrixCommand command; - @Param({"true", "false"}) - public boolean forceCircuitOpen; - @Param({"THREAD", "SEMAPHORE"}) public HystrixCommandProperties.ExecutionIsolationStrategy isolationStrategy; + @Param({"1", "100", "10000"}) + public int blackholeConsumption; @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(forceCircuitOpen) - ) - .andThreadPoolPropertiesDefaults( - HystrixThreadPoolProperties.Setter() - .withCoreSize(100) - ) + .andCommandPropertiesDefaults(getCommandSetter(isolationStrategy)) + .andThreadPoolPropertiesDefaults(threadPoolDefaults) ) { @Override protected Integer run() throws Exception { + Blackhole.consumeCPU(blackholeConsumption); return 1; } diff --git a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandGroupKeyExecutionPerfTest.java b/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandGroupKeyExecutionPerfTest.java deleted file mode 100644 index 8d3046c58..000000000 --- a/hystrix-core/src/jmh/java/com/netflix/hystrix/perf/CommandGroupKeyExecutionPerfTest.java +++ /dev/null @@ -1,197 +0,0 @@ -/** - * Copyright 2015 Netflix, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.netflix.hystrix.perf; - -import com.netflix.hystrix.HystrixCommand; -import com.netflix.hystrix.HystrixCommandGroupKey; -import com.netflix.hystrix.HystrixCommandProperties; -import com.netflix.hystrix.HystrixThreadPool; -import com.netflix.hystrix.HystrixThreadPoolKey; -import com.netflix.hystrix.HystrixThreadPoolProperties; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -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 org.openjdk.jmh.annotations.TearDown; -import rx.Observable; -import rx.schedulers.Schedulers; - -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -public class CommandGroupKeyExecutionPerfTest { - - @State(Scope.Thread) - public static class CommandState { - HystrixCommand command; - - static class TestCommand extends HystrixCommand { - TestCommand() { - super(HystrixCommandGroupKey.Factory.asKey("PERF")); - } - - @Override - protected Integer run() throws Exception { - return 1; - } - - @Override - protected Integer getFallback() { - return 2; - } - } - - @Setup(Level.Invocation) - public void setUp() { - command = new TestCommand(); - } - } - - @State(Scope.Benchmark) - public static class ExecutorState { - ExecutorService executorService; - - @Setup - public void setUp() { - executorService = Executors.newFixedThreadPool(100); - } - - @TearDown - public void tearDown() { - List runnables = executorService.shutdownNow(); - } - } - - @State(Scope.Benchmark) - public static class ThreadPoolState { - HystrixThreadPool hystrixThreadPool; - - @Setup - public void setUp() { - hystrixThreadPool = new HystrixThreadPool.HystrixThreadPoolDefault( - HystrixThreadPoolKey.Factory.asKey("PERF") - , HystrixThreadPoolProperties.Setter().withCoreSize(100)); - } - - @TearDown - public void tearDown() { - hystrixThreadPool.getExecutor().shutdownNow(); - } - } - - - @Benchmark - @BenchmarkMode({Mode.Throughput}) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public Integer baselineExecute() { - return 1; - } - - @Benchmark - @BenchmarkMode({Mode.Throughput}) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public Integer baselineQueue(ExecutorState state) throws InterruptedException, ExecutionException{ - try { - return state.executorService.submit(new Callable() { - @Override - public Integer call() throws Exception { - return 1; - } - }).get(); - } catch (Throwable t) { - return 2; - } - } - - @Benchmark - @BenchmarkMode({Mode.Throughput}) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public Integer baselineSyncObserve() throws InterruptedException { - Observable syncObservable = Observable.just(1); - - try { - return syncObservable.toBlocking().first(); - } catch (Throwable t) { - return 2; - } - } - - @Benchmark - @BenchmarkMode({Mode.Throughput}) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public Integer baselineAsyncComputationObserve() throws InterruptedException { - Observable asyncObservable = Observable.just(1).subscribeOn(Schedulers.computation()); - - try { - return asyncObservable.toBlocking().first(); - } catch (Throwable t) { - return 2; - } - } - - @Benchmark - @BenchmarkMode({Mode.Throughput}) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public Integer baselineAsyncCustomThreadPoolObserve(ThreadPoolState state) { - Observable asyncObservable = Observable.just(1).subscribeOn(state.hystrixThreadPool.getScheduler()); - try { - return asyncObservable.toBlocking().first(); - } catch (Throwable t) { - return 2; - } - } - - @Benchmark - @BenchmarkMode({Mode.Throughput}) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public Integer hystrixExecute(CommandState state) { - return state.command.execute(); - } - - @Benchmark - @BenchmarkMode({Mode.Throughput}) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public Integer hystrixQueue(CommandState state) { - try { - return state.command.queue().get(); - } catch (Throwable t) { - return 2; - } - } - - @Benchmark - @BenchmarkMode({Mode.Throughput}) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public Integer hystrixObserve(CommandState state) { - return state.command.observe().toBlocking().first(); - } - - @Benchmark - @BenchmarkMode({Mode.Throughput}) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public Integer hystrixToObservable(CommandState state) { - return state.command.toObservable().toBlocking().first(); - } -}