Skip to content

Commit

Permalink
Merge pull request #892 from mattrjacobs/cache-setter-in-multithreade…
Browse files Browse the repository at this point in the history
…d-jmh-test

Cache HystrixCommand.Setter over benchmark duration in MultiThreadedMetricsTest
  • Loading branch information
mattrjacobs committed Sep 9, 2015
2 parents 465dfab + 32c2a2d commit b21f8ca
Showing 1 changed file with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@
import java.util.concurrent.TimeUnit;

public class MultiThreadedMetricsTest {
private static HystrixCommand.Setter threadIsolatedSetter = HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("PERF"))
.andCommandPropertiesDefaults(
HystrixCommandProperties.Setter()
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD)
.withRequestCacheEnabled(true)
.withRequestLogEnabled(true)
.withCircuitBreakerEnabled(true)
.withCircuitBreakerForceOpen(false)
)
.andThreadPoolPropertiesDefaults(
HystrixThreadPoolProperties.Setter()
.withCoreSize(100)
);

private static HystrixCommand.Setter semaphoreIsolatedSetter = HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("PERF"))
.andCommandPropertiesDefaults(
HystrixCommandProperties.Setter()
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
.withRequestCacheEnabled(true)
.withRequestLogEnabled(true)
.withCircuitBreakerEnabled(true)
.withCircuitBreakerForceOpen(false)
)
.andThreadPoolPropertiesDefaults(
HystrixThreadPoolProperties.Setter()
.withCoreSize(100)
);

@State(Scope.Thread)
public static class CommandState {
HystrixCommand<Integer> command;
Expand All @@ -49,21 +77,14 @@ public static class CommandState {
@Setup(Level.Invocation)
public void setUp() {
reqContext = HystrixRequestContext.initializeContext();
command = new HystrixCommand<Integer>(
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)
)
) {
HystrixCommand.Setter cachedSetter = null;
if (isolationStrategy.equals(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD)) {
cachedSetter = threadIsolatedSetter;
} else {
cachedSetter = semaphoreIsolatedSetter;
}

command = new HystrixCommand<Integer>(cachedSetter) {
@Override
protected Integer run() throws Exception {
return 1;
Expand Down

0 comments on commit b21f8ca

Please sign in to comment.