Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added requestContext to all JMH tests, so that command flow uses (and benchmarks) them #891

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,6 +21,7 @@
import com.netflix.hystrix.HystrixThreadPool;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
Expand All @@ -46,6 +47,7 @@ public class CommandGroupKeyExecutionPerfTest {
@State(Scope.Thread)
public static class CommandState {
HystrixCommand<Integer> command;
HystrixRequestContext reqContext;

static class TestCommand extends HystrixCommand<Integer> {
TestCommand() {
Expand All @@ -65,8 +67,14 @@ protected Integer getFallback() {

@Setup(Level.Invocation)
public void setUp() {
reqContext = HystrixRequestContext.initializeContext();
command = new TestCommand();
}

@TearDown(Level.Invocation)
public void tearDown() {
reqContext.shutdown();
}
}

@State(Scope.Benchmark)
Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.netflix.hystrix.HystrixThreadPool;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
Expand All @@ -46,6 +47,7 @@ public class CommandSetterExecutionPerfTest {
@State(Scope.Thread)
public static class CommandState {
HystrixCommand<Integer> command;
HystrixRequestContext reqContext;

@Param({"true", "false"})
public boolean forceCircuitOpen;
Expand All @@ -56,6 +58,7 @@ 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(
Expand All @@ -82,6 +85,11 @@ protected Integer getFallback() {
}
};
}

@TearDown(Level.Invocation)
public void tearDown() {
reqContext.shutdown();
}
}

@State(Scope.Benchmark)
Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.netflix.hystrix.HystrixCommandMetrics;
import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Group;
Expand All @@ -31,20 +32,23 @@
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 java.util.concurrent.TimeUnit;

public class MultiThreadedMetricsTest {
@State(Scope.Thread)
public static class CommandState {
HystrixCommand<Integer> command;
HystrixRequestContext reqContext;

@Param({"THREAD", "SEMAPHORE"})
public HystrixCommandProperties.ExecutionIsolationStrategy isolationStrategy;


@Setup(Level.Invocation)
public void setUp() {
reqContext = HystrixRequestContext.initializeContext();
command = new HystrixCommand<Integer>(
HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("PERF"))
.andCommandPropertiesDefaults(
Expand All @@ -71,6 +75,11 @@ protected Integer getFallback() {
}
};
}

@TearDown(Level.Invocation)
public void tearDown() {
reqContext.shutdown();
}
}

@Benchmark
Expand Down