diff --git a/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/mvc/SleuthBenchmarkingSpringApp.java b/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/mvc/SleuthBenchmarkingSpringApp.java index a060fa836..67b51420c 100644 --- a/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/mvc/SleuthBenchmarkingSpringApp.java +++ b/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/mvc/SleuthBenchmarkingSpringApp.java @@ -16,10 +16,6 @@ package org.springframework.cloud.sleuth.benchmarks.app.mvc; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.regex.Pattern; @@ -40,15 +36,13 @@ import org.springframework.cloud.sleuth.Tracer; import org.springframework.cloud.sleuth.annotation.ContinueSpan; import org.springframework.cloud.sleuth.annotation.NewSpan; import org.springframework.cloud.sleuth.annotation.SpanTag; +import org.springframework.cloud.sleuth.benchmarks.app.mvc.controller.AsyncSimulationController; import org.springframework.cloud.sleuth.instrument.web.SkipPatternProvider; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.util.SocketUtils; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; /** * @author Marcin Grzejszczak @@ -71,7 +65,7 @@ public class SleuthBenchmarkingSpringApp implements ApplicationListener async() { - return this.aController.async(); + return this.controller.async(); } @Configuration @@ -134,41 +128,6 @@ public class SleuthBenchmarkingSpringApp implements ApplicationListener bar() { - return () -> "bar"; - } - - @RequestMapping("/async") - public String asyncHttp() throws ExecutionException, InterruptedException { - return this.async().get(); - } - - @Async - public Future async() { - return this.pool.submit(() -> "async"); - } - - @PreDestroy - public void clean() { - this.pool.shutdownNow(); - } - - public ExecutorService getPool() { - return this.pool; - } -} - class AClass { private final Tracer tracer; diff --git a/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/mvc/controller/AsyncSimulationController.java b/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/mvc/controller/AsyncSimulationController.java new file mode 100644 index 000000000..94b17fdd8 --- /dev/null +++ b/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/mvc/controller/AsyncSimulationController.java @@ -0,0 +1,50 @@ +package org.springframework.cloud.sleuth.benchmarks.app.mvc.controller; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import javax.annotation.PreDestroy; + +import org.springframework.scheduling.annotation.Async; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author Marcin Grzejszczak + */ +@RestController +public class AsyncSimulationController { + private final ExecutorService pool = Executors.newWorkStealingPool(); + + @RequestMapping("/foo") + public String foo() { + return "foo"; + } + + @RequestMapping("/bar") + public Callable bar() { + return () -> "bar"; + } + + @RequestMapping("/async") + public String asyncHttp() throws ExecutionException, InterruptedException { + return this.async().get(); + } + + @Async + public Future async() { + return this.pool.submit(() -> "async"); + } + + @PreDestroy + public void clean() { + this.pool.shutdownNow(); + } + + public ExecutorService getPool() { + return this.pool; + } +} diff --git a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/HttpFilterBenchmarksTests.java b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/HttpFilterBenchmarksTests.java index 229ca844f..91570bf0c 100644 --- a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/HttpFilterBenchmarksTests.java +++ b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/HttpFilterBenchmarksTests.java @@ -45,6 +45,7 @@ import org.openjdk.jmh.annotations.Warmup; import org.springframework.boot.SpringApplication; import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpringApp; import org.springframework.cloud.sleuth.benchmarks.jmh.TracerImplementation; +import org.springframework.cloud.sleuth.benchmarks.app.mvc.controller.AsyncSimulationController; import org.springframework.cloud.sleuth.instrument.web.servlet.TracingFilter; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.http.MediaType; @@ -143,7 +144,7 @@ public class HttpFilterBenchmarksTests { "--spring.application.name=withSleuth_" + this.tracerImplementation.name()); this.tracingFilter = this.withSleuth.getBean(TracingFilter.class); this.mockMvcForTracedController = MockMvcBuilders - .standaloneSetup(this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class)).build(); + .standaloneSetup(this.withSleuth.getBean(AsyncSimulationController.class)).build(); this.mockMvcForUntracedController = MockMvcBuilders.standaloneSetup(new VanillaController()).build(); }