Applied checkstyle

This commit is contained in:
Marcin Grzejszczak
2019-02-07 16:41:59 +01:00
parent 37df4c4df8
commit 2f7cf78614
380 changed files with 7749 additions and 5259 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import javax.annotation.PreDestroy;
import brave.Span;
@@ -29,6 +30,7 @@ import brave.Tracer;
import brave.sampler.Sampler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
@@ -54,8 +56,8 @@ import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
@EnableAsync
public class SleuthBenchmarkingSpringApp implements
ApplicationListener<ServletWebServerInitializedEvent> {
public class SleuthBenchmarkingSpringApp
implements ApplicationListener<ServletWebServerInitializedEvent> {
private static final Log log = LogFactory.getLog(SleuthBenchmarkingSpringApp.class);
@@ -63,8 +65,15 @@ public class SleuthBenchmarkingSpringApp implements
public int port;
@Autowired(required = false) Tracer tracer;
@Autowired AClass aClass;
@Autowired(required = false)
Tracer tracer;
@Autowired
AClass aClass;
public static void main(String... args) {
SpringApplication.run(SleuthBenchmarkingSpringApp.class, args);
}
@RequestMapping("/foo")
public String foo() {
@@ -100,9 +109,11 @@ public class SleuthBenchmarkingSpringApp implements
}
@Bean
public ServletWebServerFactory servletContainer(@Value("${server.port:0}") int serverPort) {
public ServletWebServerFactory servletContainer(
@Value("${server.port:0}") int serverPort) {
log.info("Starting container at port [" + serverPort + "]");
return new TomcatServletWebServerFactory(serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
return new TomcatServletWebServerFactory(
serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
}
@PreDestroy
@@ -110,21 +121,26 @@ public class SleuthBenchmarkingSpringApp implements
this.pool.shutdownNow();
}
@Bean Sampler alwaysSampler() {
@Bean
Sampler alwaysSampler() {
return Sampler.ALWAYS_SAMPLE;
}
@Bean AnotherClass anotherClass() {
@Bean
AnotherClass anotherClass() {
return new AnotherClass(this.tracer);
}
@Bean AClass aClass() {
@Bean
AClass aClass() {
return new AClass(this.tracer, anotherClass());
}
@Bean SkipPatternProvider patternProvider() {
@Bean
SkipPatternProvider patternProvider() {
return new SkipPatternProvider() {
@Override public Pattern skipPattern() {
@Override
public Pattern skipPattern() {
return Pattern.compile("");
}
};
@@ -134,12 +150,12 @@ public class SleuthBenchmarkingSpringApp implements
return this.pool;
}
public static void main(String... args) {
SpringApplication.run(SleuthBenchmarkingSpringApp.class, args);
}
}
class AClass {
private final Tracer tracer;
private final AnotherClass anotherClass;
AClass(Tracer tracer, AnotherClass anotherClass) {
@@ -151,7 +167,8 @@ class AClass {
Span manual = this.tracer.nextSpan().name("span-name");
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(manual.start())) {
return this.anotherClass.continuedSpan();
} finally {
}
finally {
manual.finish();
}
}
@@ -160,9 +177,11 @@ class AClass {
public String newSpan() {
return this.anotherClass.continuedAnnotation("bar");
}
}
class AnotherClass {
private final Tracer tracer;
AnotherClass(Tracer tracer) {
@@ -182,4 +201,5 @@ class AnotherClass {
span.annotate("continuedspan.after");
return response;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,14 +14,17 @@
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.app.webflux;
import brave.Tracer;
import java.util.regex.Pattern;
import brave.sampler.Sampler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import reactor.core.publisher.Mono;
import zipkin2.Span;
import zipkin2.reporter.Reporter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -34,24 +37,25 @@ import org.springframework.context.annotation.Bean;
import org.springframework.util.SocketUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import zipkin2.Span;
import zipkin2.reporter.Reporter;
import java.util.regex.Pattern;
/**
* @author alvin
*/
@SpringBootApplication
@RestController
public class SleuthBenchmarkingSpringWebFluxApp implements ApplicationListener<ReactiveWebServerInitializedEvent> {
public class SleuthBenchmarkingSpringWebFluxApp
implements ApplicationListener<ReactiveWebServerInitializedEvent> {
private static final Log log = LogFactory.getLog(SleuthBenchmarkingSpringWebFluxApp.class);
private static final Log log = LogFactory
.getLog(SleuthBenchmarkingSpringWebFluxApp.class);
public int port;
public static void main(String... args) {
new SpringApplicationBuilder(SleuthBenchmarkingSpringWebFluxApp.class)
.web(WebApplicationType.REACTIVE).application().run(args);
}
@RequestMapping("/foo")
public Mono<String> foo() {
return Mono.just("foo");
@@ -67,18 +71,12 @@ public class SleuthBenchmarkingSpringWebFluxApp implements ApplicationListener<R
return () -> Pattern.compile("");
}
@Bean
NettyReactiveWebServerFactory nettyReactiveWebServerFactory(@Value("${server.port:0}") int serverPort) {
NettyReactiveWebServerFactory nettyReactiveWebServerFactory(
@Value("${server.port:0}") int serverPort) {
log.info("Starting container at port [" + serverPort + "]");
return new NettyReactiveWebServerFactory(serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
}
public static void main(String... args) {
new SpringApplicationBuilder(SleuthBenchmarkingSpringWebFluxApp.class)
.web(WebApplicationType.REACTIVE)
.application()
.run(args);
return new NettyReactiveWebServerFactory(
serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
}
@Bean
@@ -86,11 +84,9 @@ public class SleuthBenchmarkingSpringWebFluxApp implements ApplicationListener<R
return Reporter.NOOP;
}
@Override
public void onApplicationEvent(ReactiveWebServerInitializedEvent event) {
this.port = event.getWebServer().getPort();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpringApp;
import org.springframework.context.ConfigurableApplicationContext;
@@ -44,35 +45,37 @@ import static org.assertj.core.api.BDDAssertions.then;
@Threads(Threads.MAX)
public class AnnotationBenchmarks {
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile SleuthBenchmarkingSpringApp sleuth;
@Setup public void setup() {
this.withSleuth = new SpringApplication(
SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.sleuth = this.withSleuth.getBean(
SleuthBenchmarkingSpringApp.class);
}
@TearDown public void clean() {
this.sleuth.clean();
this.withSleuth.close();
}
}
@Benchmark
public void manuallyCreatedSpans(BenchmarkContext context)
throws Exception {
public void manuallyCreatedSpans(BenchmarkContext context) throws Exception {
then(context.sleuth.manualSpan()).isEqualTo("continued");
}
@Benchmark
public void spanCreatedWithAnnotations(BenchmarkContext context)
throws Exception {
public void spanCreatedWithAnnotations(BenchmarkContext context) throws Exception {
then(context.sleuth.newSpan()).isEqualTo("continued");
}
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile SleuthBenchmarkingSpringApp sleuth;
@Setup
public void setup() {
this.withSleuth = new SpringApplication(SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.sleuth = this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class);
}
@TearDown
public void clean() {
this.sleuth.clean();
this.withSleuth.close();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import java.util.concurrent.TimeUnit;
@@ -29,6 +30,7 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpringApp;
import org.springframework.context.ConfigurableApplicationContext;
@@ -43,47 +45,51 @@ import static org.assertj.core.api.BDDAssertions.then;
@Threads(Threads.MAX)
public class AsyncBenchmarks {
@Benchmark
public void asyncMethodWithoutSleuth(BenchmarkContext context) throws Exception {
then(context.untracedAsyncMethodHavingBean.async().get()).isEqualTo("async");
}
@Benchmark
public void asyncMethodWithSleuth(BenchmarkContext context) throws Exception {
then(context.tracedAsyncMethodHavingBean.async().get()).isEqualTo("async");
}
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile ConfigurableApplicationContext withoutSleuth;
volatile SleuthBenchmarkingSpringApp tracedAsyncMethodHavingBean;
volatile SleuthBenchmarkingSpringApp untracedAsyncMethodHavingBean;
@Setup public void setup() {
this.withSleuth = new SpringApplication(
SleuthBenchmarkingSpringApp.class)
@Setup
public void setup() {
this.withSleuth = new SpringApplication(SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.withoutSleuth = new SpringApplication(
SleuthBenchmarkingSpringApp.class)
this.withoutSleuth = new SpringApplication(SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withoutSleuth",
"--spring.sleuth.enabled=false",
"--spring.sleuth.async.enabled=false");
this.tracedAsyncMethodHavingBean = this.withSleuth.getBean(
SleuthBenchmarkingSpringApp.class);
this.untracedAsyncMethodHavingBean = this.withoutSleuth.getBean(
SleuthBenchmarkingSpringApp.class);
this.tracedAsyncMethodHavingBean = this.withSleuth
.getBean(SleuthBenchmarkingSpringApp.class);
this.untracedAsyncMethodHavingBean = this.withoutSleuth
.getBean(SleuthBenchmarkingSpringApp.class);
}
@TearDown public void clean() {
@TearDown
public void clean() {
this.tracedAsyncMethodHavingBean.clean();
this.untracedAsyncMethodHavingBean.clean();
this.withSleuth.close();
this.withoutSleuth.close();
}
}
@Benchmark
public void asyncMethodWithoutSleuth(BenchmarkContext context)
throws Exception {
then(context.untracedAsyncMethodHavingBean.async().get()).isEqualTo("async");
}
@Benchmark
public void asyncMethodWithSleuth(BenchmarkContext context)
throws Exception {
then(context.tracedAsyncMethodHavingBean.async().get()).isEqualTo("async");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -38,6 +40,7 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpringApp;
import org.springframework.context.ConfigurableApplicationContext;
@@ -65,35 +68,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@Threads(Threads.MAX)
public class HttpFilterBenchmarks {
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile DummyFilter dummyFilter = new DummyFilter();
volatile TracingFilter tracingFilter;
volatile MockMvc mockMvcForTracedController;
volatile MockMvc mockMvcForUntracedController;
@Setup public void setup() {
this.withSleuth = new SpringApplication(
SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.tracingFilter = this.withSleuth.getBean(TracingFilter.class);
this.mockMvcForTracedController = MockMvcBuilders.standaloneSetup(
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class))
.build();
this.mockMvcForUntracedController = MockMvcBuilders.standaloneSetup(
new VanillaController())
.build();
}
@TearDown public void clean() {
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class).clean();
this.withSleuth.close();
}
}
@Benchmark
@Measurement(iterations = 5, time = 1)
@Fork(3)
@@ -133,38 +107,80 @@ public class HttpFilterBenchmarks {
}
private MockHttpServletRequestBuilder builder() {
return get("/").accept(MediaType.APPLICATION_JSON)
.header("User-Agent", "MockMvc");
return get("/").accept(MediaType.APPLICATION_JSON).header("User-Agent",
"MockMvc");
}
private void performRequest(MockMvc mockMvc, String url, String expectedResult) throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/" + url))
.andExpect(status().isOk())
.andExpect(request().asyncStarted())
.andReturn();
private void performRequest(MockMvc mockMvc, String url, String expectedResult)
throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/" + url)).andExpect(status().isOk())
.andExpect(request().asyncStarted()).andReturn();
mockMvc.perform(asyncDispatch(mvcResult))
.andExpect(status().isOk())
mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk())
.andExpect(content().string(expectedResult));
}
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile DummyFilter dummyFilter = new DummyFilter();
volatile TracingFilter tracingFilter;
volatile MockMvc mockMvcForTracedController;
volatile MockMvc mockMvcForUntracedController;
@Setup
public void setup() {
this.withSleuth = new SpringApplication(SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.tracingFilter = this.withSleuth.getBean(TracingFilter.class);
this.mockMvcForTracedController = MockMvcBuilders
.standaloneSetup(
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class))
.build();
this.mockMvcForUntracedController = MockMvcBuilders
.standaloneSetup(new VanillaController()).build();
}
@TearDown
public void clean() {
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class).clean();
this.withSleuth.close();
}
}
private static class DummyFilter implements Filter {
@Override public void init(FilterConfig filterConfig) throws ServletException {}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override public void doFilter(ServletRequest request, ServletResponse response,
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}
@Override public void destroy() { }
@Override
public void destroy() {
}
}
@RestController
private static class VanillaController {
@RequestMapping("/vanilla")
public Callable<String> vanilla() {
return () -> "vanilla";
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import java.io.BufferedReader;
@@ -35,10 +36,15 @@ import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpr
public class ProcessLauncherState {
private Process started;
private List<String> args;
private List<String> extraArgs;
private File home;
private String mainClass = SleuthBenchmarkingSpringApp.class.getName();
private int length;
public ProcessLauncherState(String dir, String... args) {
@@ -58,6 +64,21 @@ public class ProcessLauncherState {
this.home = new File(dir);
}
protected static String output(InputStream inputStream, String marker)
throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while ((line = br.readLine()) != null && !line.contains(marker)) {
sb.append(line + System.getProperty("line.separator"));
}
if (line != null) {
sb.append(line + System.getProperty("line.separator"));
}
return sb.toString();
}
public void setMainClass(String mainClass) {
this.mainClass = mainClass;
}
@@ -101,7 +122,7 @@ public class ProcessLauncherState {
public void run() throws Exception {
List<String> args = new ArrayList<>(this.args);
args.add(args.size() - this.length, this.mainClass);
if (extraArgs!=null) {
if (extraArgs != null) {
args.addAll(extraArgs);
}
ProcessBuilder builder = new ProcessBuilder(args);
@@ -122,22 +143,8 @@ public class ProcessLauncherState {
System.out.println(output(started.getInputStream(), "Started"));
}
protected static String output(InputStream inputStream, String marker)
throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while ((line = br.readLine()) != null && !line.contains(marker)) {
sb.append(line + System.getProperty("line.separator"));
}
if (line != null) {
sb.append(line + System.getProperty("line.separator"));
}
return sb.toString();
}
public File getHome() {
return home;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import brave.spring.web.TracingClientHttpRequestInterceptor;
@@ -33,6 +35,7 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpringApp;
import org.springframework.context.ConfigurableApplicationContext;
@@ -44,8 +47,7 @@ import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.BDDAssertions.then;
/**
* We're checking how much overhead does the instrumentation
* of the RestTemplate take
* We're checking how much overhead does the instrumentation of the RestTemplate take
*/
@Measurement(iterations = 5)
@Warmup(iterations = 10)
@@ -55,20 +57,37 @@ import static org.assertj.core.api.BDDAssertions.then;
@Threads(Threads.MAX)
public class RestTemplateBenchmark {
@Benchmark
public void syncEndpointWithoutSleuth(BenchmarkContext context)
throws IOException, ServletException {
then(context.untracedTemplate.getForObject("/foo", String.class))
.isEqualTo("foo");
}
@Benchmark
public void syncEndpointWithSleuth(BenchmarkContext context)
throws ServletException, IOException {
then(context.tracedTemplate.getForObject("/foo", String.class)).isEqualTo("foo");
}
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile MockMvc mockMvc;
volatile RestTemplate tracedTemplate;
volatile RestTemplate untracedTemplate;
@Setup public void setup() {
new SpringApplication(
SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.mockMvc = MockMvcBuilders.standaloneSetup(
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class))
@Setup
public void setup() {
new SpringApplication(SleuthBenchmarkingSpringApp.class).run(
"--spring.jmx.enabled=false", "--spring.application.name=withSleuth");
this.mockMvc = MockMvcBuilders
.standaloneSetup(
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class))
.build();
this.tracedTemplate = new RestTemplate(
new MockMvcClientHttpRequestFactory(this.mockMvc));
@@ -78,22 +97,12 @@ public class RestTemplateBenchmark {
new MockMvcClientHttpRequestFactory(this.mockMvc));
}
@TearDown public void clean() {
@TearDown
public void clean() {
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class).clean();
this.withSleuth.close();
}
}
@Benchmark
public void syncEndpointWithoutSleuth(BenchmarkContext context)
throws IOException, ServletException {
then(context.untracedTemplate.getForObject("/foo", String.class)).isEqualTo("foo");
}
@Benchmark
public void syncEndpointWithSleuth(BenchmarkContext context)
throws ServletException, IOException {
then(context.tracedTemplate.getForObject("/foo", String.class)).isEqualTo("foo");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,8 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.httpclient.TracingHttpClientBuilder;
@@ -41,15 +45,13 @@ import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import zipkin2.reporter.Reporter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.sleuth.benchmarks.app.webflux.SleuthBenchmarkingSpringWebFluxApp;
import org.springframework.context.ConfigurableApplicationContext;
import zipkin2.reporter.Reporter;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 10, time = 1)
@@ -60,31 +62,34 @@ import java.util.concurrent.TimeUnit;
@State(Scope.Benchmark)
public class SpringWebFluxBenchmarks {
protected static TraceContext defaultTraceContext = TraceContext.newBuilder()
.traceIdHigh(333L).traceId(444L).spanId(3).sampled(true).build();
protected ConfigurableApplicationContext applicationContext;
protected SleuthBenchmarkingSpringWebFluxApp springWebFluxApp;
CloseableHttpClient client;
CloseableHttpClient tracedClient;
CloseableHttpClient unsampledClient;
private String baseUrl;
protected static TraceContext defaultTraceContext =
TraceContext.newBuilder().traceIdHigh(333L).traceId(444L).spanId(3).sampled(true).build();
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + SpringWebFluxBenchmarks.class.getSimpleName() + ".*")
.build();
new Runner(opt).run();
}
public String getBaseUrl() {
return baseUrl;
}
private String baseUrl;
protected CloseableHttpClient newClient(HttpTracing httpTracing) {
return TracingHttpClientBuilder.create(httpTracing)
.disableAutomaticRetries()
return TracingHttpClientBuilder.create(httpTracing).disableAutomaticRetries()
.build();
}
protected CloseableHttpClient newClient() {
return HttpClients.custom()
.disableAutomaticRetries()
.build();
return HttpClients.custom().disableAutomaticRetries().build();
}
protected void get(CloseableHttpClient client) throws Exception {
@@ -95,31 +100,27 @@ public class SpringWebFluxBenchmarks {
client.close();
}
@Setup
public void setup() {
ConfigurableApplicationContext context = initContext();
this.applicationContext = context;
this.springWebFluxApp = this.applicationContext.getBean(
SleuthBenchmarkingSpringWebFluxApp.class);
this.springWebFluxApp = this.applicationContext
.getBean(SleuthBenchmarkingSpringWebFluxApp.class);
baseUrl = "http://127.0.0.1:" + springWebFluxApp.port + "/foo";
client = newClient();
tracedClient = newClient(HttpTracing.create(
Tracing.newBuilder().spanReporter(Reporter.NOOP).build()
));
unsampledClient = newClient(HttpTracing.create(
Tracing.newBuilder().sampler(Sampler.NEVER_SAMPLE).spanReporter(Reporter.NOOP).build()
));
tracedClient = newClient(HttpTracing
.create(Tracing.newBuilder().spanReporter(Reporter.NOOP).build()));
unsampledClient = newClient(HttpTracing.create(Tracing.newBuilder()
.sampler(Sampler.NEVER_SAMPLE).spanReporter(Reporter.NOOP).build()));
postSetUp();
}
protected ConfigurableApplicationContext initContext() {
SpringApplication application = new SpringApplicationBuilder(SleuthBenchmarkingSpringWebFluxApp.class)
.web(WebApplicationType.REACTIVE)
.application();
SpringApplication application = new SpringApplicationBuilder(
SleuthBenchmarkingSpringWebFluxApp.class).web(WebApplicationType.REACTIVE)
.application();
customSpringApplication(application);
return application
.run(runArgs());
return application.run(runArgs());
}
protected void customSpringApplication(SpringApplication springApplication) {
@@ -129,14 +130,12 @@ public class SpringWebFluxBenchmarks {
protected void postSetUp() {
}
protected String[] runArgs() {
return new String[]{"--spring.jmx.enabled=false",
return new String[] { "--spring.jmx.enabled=false",
"--spring.application.name=defaultTraceContext",
"--spring.sleuth.enabled=true"};
"--spring.sleuth.enabled=true" };
}
@TearDown
public void clean() throws Exception {
close(client);
@@ -146,7 +145,8 @@ public class SpringWebFluxBenchmarks {
try {
this.applicationContext.close();
} catch (Exception ig) {
}
catch (Exception ig) {
}
}
@@ -168,18 +168,10 @@ public class SpringWebFluxBenchmarks {
@Benchmark
public void tracedClient_get_resumeTrace() throws Exception {
try (CurrentTraceContext.Scope scope = Tracing.current().currentTraceContext().newScope(defaultTraceContext)) {
try (CurrentTraceContext.Scope scope = Tracing.current().currentTraceContext()
.newScope(defaultTraceContext)) {
get(tracedClient);
}
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + SpringWebFluxBenchmarks.class.getSimpleName() + ".*")
.build();
new Runner(opt).run();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import org.openjdk.jmh.annotations.Benchmark;
@@ -42,27 +43,34 @@ public class StartupBenchmark {
state.setExtraArgs("--spring.sleuth.annotation.enabled=false");
state.run();
}
@Benchmark
public void withoutAsync(ApplicationState state) throws Exception {
state.setExtraArgs("--spring.sleuth.async.enabled=false", "--spring.sleuth.annotation.enabled=false");
state.setExtraArgs("--spring.sleuth.async.enabled=false",
"--spring.sleuth.annotation.enabled=false");
state.run();
}
@Benchmark
public void withoutScheduled(ApplicationState state) throws Exception {
state.setExtraArgs("--spring.sleuth.scheduled.enabled=false", "--spring.sleuth.async.enabled=false", "--spring.sleuth.annotation.enabled=false");
state.setExtraArgs("--spring.sleuth.scheduled.enabled=false",
"--spring.sleuth.async.enabled=false",
"--spring.sleuth.annotation.enabled=false");
state.run();
}
@Benchmark
public void withoutWeb(ApplicationState state) throws Exception {
state.setExtraArgs("--spring.sleuth.web.enabled=false", "--spring.sleuth.scheduled.enabled=false", "--spring.sleuth.async.enabled=false", "--spring.sleuth.annotation.enabled=false");
state.setExtraArgs("--spring.sleuth.web.enabled=false",
"--spring.sleuth.scheduled.enabled=false",
"--spring.sleuth.async.enabled=false",
"--spring.sleuth.annotation.enabled=false");
state.run();
}
@State(Scope.Benchmark)
public static class ApplicationState extends ProcessLauncherState {
public ApplicationState() {
super("target", "--server.port=0");
}
@@ -71,6 +79,7 @@ public class StartupBenchmark {
public void stop() throws Exception {
super.after();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import org.openjdk.jmh.runner.Runner;
@@ -25,12 +26,20 @@ import org.openjdk.jmh.runner.options.OptionsBuilder;
*/
public class WithOutReactorSleuthSpringWebFluxBenchmarks extends SpringWebFluxBenchmarks {
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder().include(
".*" + WithOutReactorSleuthSpringWebFluxBenchmarks.class.getSimpleName()
+ ".*")
.build();
new Runner(opt).run();
}
@Override
protected String[] runArgs() {
return new String[]{"--spring.jmx.enabled=false",
return new String[] { "--spring.jmx.enabled=false",
"--spring.application.name=defaultTraceContext",
"--spring.sleuth.enabled=true",
"--spring.sleuth.reactor.enabled=false"
"--spring.sleuth.enabled=true", "--spring.sleuth.reactor.enabled=false"
};
}
@@ -40,11 +49,4 @@ public class WithOutReactorSleuthSpringWebFluxBenchmarks extends SpringWebFluxBe
super.postSetUp();
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + WithOutReactorSleuthSpringWebFluxBenchmarks.class.getSimpleName() + ".*")
.build();
new Runner(opt).run();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import org.openjdk.jmh.runner.Runner;
@@ -25,11 +26,19 @@ import org.openjdk.jmh.runner.options.OptionsBuilder;
*/
public class WithOutSleuthSpringWebFluxBenchmarks extends SpringWebFluxBenchmarks {
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder().include(
".*" + WithOutSleuthSpringWebFluxBenchmarks.class.getSimpleName() + ".*")
.build();
new Runner(opt).run();
}
@Override
protected String[] runArgs() {
return new String[]{"--spring.jmx.enabled=false",
return new String[] { "--spring.jmx.enabled=false",
"--spring.application.name=defaultTraceContext",
"--spring.sleuth.enabled=false"};
"--spring.sleuth.enabled=false" };
}
@Override
@@ -37,11 +46,4 @@ public class WithOutSleuthSpringWebFluxBenchmarks extends SpringWebFluxBenchmark
super.postSetUp();
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + WithOutSleuthSpringWebFluxBenchmarks.class.getSimpleName() + ".*")
.build();
new Runner(opt).run();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,9 +26,11 @@ public class RunSleuthJmhBenchmarksFromIde {
// Convenience main entry-point for testing from IDE
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(RunSleuthJmhBenchmarksFromIde.class.getPackage().getName() + ".benchmarks.*")
.include(RunSleuthJmhBenchmarksFromIde.class.getPackage().getName()
+ ".benchmarks.*")
.build();
new Runner(opt).run();
}
}
}

View File

@@ -13,5 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
sampleresult.useNanoTime=true