From f8245ac7698764aa8a7e515584bd0136fc7c6b78 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 26 Nov 2020 10:40:46 +0100 Subject: [PATCH] Fixed benchmarks --- .../SleuthBenchmarkingStreamApplication.java | 28 ++++++++++--------- .../SleuthBenchmarkingSpringWebFluxApp.java | 12 ++++++-- .../benchmarks/jmh/bridge/BridgeTests.java | 12 +++++--- .../jmh/mvc/AnnotationBenchmarksTests.java | 2 +- .../jmh/mvc/AsyncBenchmarksTests.java | 2 +- .../jmh/mvc/RestTemplateBenchmarkTests.java | 2 +- .../jmh/stream/MicroBenchmarkStreamTests.java | 9 ++++-- .../jmh/webflux/MicroBenchmarkHttpTests.java | 2 +- .../webflux/SpringWebFluxBenchmarksTests.java | 4 +-- .../reactor/SleuthReactorProperties.java | 4 +++ 10 files changed, 50 insertions(+), 27 deletions(-) diff --git a/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/stream/SleuthBenchmarkingStreamApplication.java b/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/stream/SleuthBenchmarkingStreamApplication.java index bde195d0d..c8aa01ed6 100644 --- a/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/stream/SleuthBenchmarkingStreamApplication.java +++ b/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/stream/SleuthBenchmarkingStreamApplication.java @@ -50,6 +50,8 @@ import static org.assertj.core.api.Assertions.assertThat; @Import(TestChannelBinderConfiguration.class) public class SleuthBenchmarkingStreamApplication { + private static final Logger log = LoggerFactory.getLogger(SleuthBenchmarkingStreamApplication.class); + public static void main(String[] args) throws InterruptedException, IOException { // System.setProperty("spring.sleuth.enabled", "false"); // System.setProperty("spring.sleuth.reactor.instrumentation-type", @@ -64,16 +66,16 @@ public class SleuthBenchmarkingStreamApplication { InputDestination input = context.getBean(InputDestination.class); input.send(MessageBuilder.withPayload("hello".getBytes()) .setHeader("b3", "4883117762eb9420-4883117762eb9420-1").build()); - System.out.println("Retrieving the message for tests"); + log.info("Retrieving the message for tests"); OutputDestination output = context.getBean(OutputDestination.class); Message message = output.receive(200L); - System.out.println("Got the message from output"); + log.info("Got the message from output"); assertThat(message).isNotNull(); - System.out.println("Message is not null"); + log.info("Message is not null"); assertThat(message.getPayload()).isEqualTo("HELLO".getBytes()); - System.out.println("Payload is HELLO"); + log.info("Payload is HELLO"); String b3 = message.getHeaders().get("b3", String.class); - System.out.println("Checking the b3 header [" + b3 + "]"); + log.info("Checking the b3 header [" + b3 + "]"); assertThat(b3).startsWith("4883117762eb9420"); } } @@ -86,42 +88,42 @@ public class SleuthBenchmarkingStreamApplication { @Bean(name = "myFlux") @ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "simple") public Function simple() { - System.out.println("simple_function"); + log.info("simple_function"); return new SimpleFunction(); } @Bean(name = "myFlux") @ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "reactive_simple") public Function, Flux> reactiveSimple() { - System.out.println("simple_reactive_function"); + log.info("simple_reactive_function"); return new SimpleReactiveFunction(); } @Bean(name = "myFlux") @ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "simple_function_with_around") public Function, Message> simpleFunctionWithAround() { - System.out.println("simple_function_with_around"); + log.info("simple_function_with_around"); return new SimpleMessageFunction(); } @Bean(name = "myFlux") @ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "simple_manual") public Function, Message> simpleManual(BeanFactory beanFactory) { - System.out.println("simple_manual_function"); + log.info("simple_manual_function"); return new SimpleManualFunction(beanFactory); } @Bean(name = "myFlux") @ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "reactive_simple_manual") public Function>, Flux>> reactiveSimpleManual(BeanFactory beanFactory) { - System.out.println("simple_reactive_manual_function"); + log.info("simple_reactive_manual_function"); return new SimpleReactiveManualFunction(beanFactory); } @Bean(name = "myFlux") @ConditionalOnProperty(value = "spring.sleuth.nonreactive.function.enabled", havingValue = "true") public Function nonReactiveFunction(ExecutorService executorService) { - System.out.println("no sleuth non reactive function"); + log.info("no sleuth non reactive function"); return new SleuthNonReactiveFunction(executorService); } @@ -129,14 +131,14 @@ public class SleuthBenchmarkingStreamApplication { @ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "DECORATE_ON_EACH", matchIfMissing = true) public Function, Flux> onEachFunction() { - System.out.println("on each function"); + log.info("on each function"); return new SleuthFunction(); } @Bean(name = "myFlux") @ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "DECORATE_ON_LAST") public Function, Flux> onLastFunction() { - System.out.println("on last function"); + log.info("on last function"); return new SleuthFunction(); } diff --git a/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/webflux/SleuthBenchmarkingSpringWebFluxApp.java b/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/webflux/SleuthBenchmarkingSpringWebFluxApp.java index 1cbf460a1..ac61085db 100644 --- a/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/webflux/SleuthBenchmarkingSpringWebFluxApp.java +++ b/benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/webflux/SleuthBenchmarkingSpringWebFluxApp.java @@ -121,7 +121,11 @@ public class SleuthBenchmarkingSpringWebFluxApp implements ApplicationListener log.info("Doing assertions")); TraceContext traceContext = signal.getContext().get(TraceContext.class); Assert.notNull(traceContext, "Context must be set by Sleuth instrumentation"); - Assert.state(traceContext.traceId().equals("4883117762eb9420"), "TraceId must be propagated"); + if (traceContext.traceId().startsWith("0000000000000000")) { + Assert.state(traceContext.traceId().equals("00000000000000004883117762eb9420"), "TraceId must be propagated"); + } else { + Assert.state(traceContext.traceId().equals("4883117762eb9420"), "TraceId must be propagated"); + } log.info("Assertions passed"); }); } diff --git a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/bridge/BridgeTests.java b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/bridge/BridgeTests.java index 780f07ad1..3f193f3a5 100644 --- a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/bridge/BridgeTests.java +++ b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/bridge/BridgeTests.java @@ -16,12 +16,15 @@ package org.springframework.cloud.sleuth.benchmarks.jmh.bridge; +import java.util.concurrent.TimeUnit; + import jmh.mbr.junit5.Microbenchmark; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Measurement; 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; @@ -42,10 +45,11 @@ import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.BDDAssertions.then; -@Measurement(iterations = 5) -@Warmup(iterations = 1) -@Fork(value = 2, warmups = 0) -@BenchmarkMode(Mode.AverageTime) +@Measurement(iterations = 5, time = 1) +@Warmup(iterations = 5, time = 1) +@Fork(2) +@BenchmarkMode(Mode.SampleTime) +@OutputTimeUnit(TimeUnit.MILLISECONDS) @Microbenchmark public class BridgeTests { diff --git a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/AnnotationBenchmarksTests.java b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/AnnotationBenchmarksTests.java index f6b85f006..7de0ede9b 100644 --- a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/AnnotationBenchmarksTests.java +++ b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/AnnotationBenchmarksTests.java @@ -41,7 +41,7 @@ import org.springframework.context.ConfigurableApplicationContext; import static org.assertj.core.api.BDDAssertions.then; @Measurement(iterations = 5, time = 1) -@Warmup(iterations = 10, time = 1) +@Warmup(iterations = 5, time = 1) @Fork(2) @BenchmarkMode(Mode.SampleTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) diff --git a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/AsyncBenchmarksTests.java b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/AsyncBenchmarksTests.java index c8c970be3..3ab976788 100644 --- a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/AsyncBenchmarksTests.java +++ b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/AsyncBenchmarksTests.java @@ -41,7 +41,7 @@ import org.springframework.context.ConfigurableApplicationContext; import static org.assertj.core.api.BDDAssertions.then; @Measurement(iterations = 5, time = 1) -@Warmup(iterations = 10, time = 1) +@Warmup(iterations = 5, time = 1) @Fork(2) @BenchmarkMode(Mode.SampleTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) diff --git a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/RestTemplateBenchmarkTests.java b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/RestTemplateBenchmarkTests.java index 64e6f0b20..c3378d389 100644 --- a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/RestTemplateBenchmarkTests.java +++ b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/RestTemplateBenchmarkTests.java @@ -53,7 +53,7 @@ import static org.assertj.core.api.BDDAssertions.then; * We're checking how much overhead does the instrumentation of the RestTemplate take */ @Measurement(iterations = 5, time = 1) -@Warmup(iterations = 10, time = 1) +@Warmup(iterations = 5, time = 1) @Fork(2) @BenchmarkMode(Mode.SampleTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) diff --git a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/stream/MicroBenchmarkStreamTests.java b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/stream/MicroBenchmarkStreamTests.java index 7b715850a..d80d303fa 100644 --- a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/stream/MicroBenchmarkStreamTests.java +++ b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/stream/MicroBenchmarkStreamTests.java @@ -58,7 +58,7 @@ import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; @Measurement(iterations = 5, time = 1) -@Warmup(iterations = 10, time = 1) +@Warmup(iterations = 5, time = 1) @Fork(2) @BenchmarkMode(Mode.SampleTime) @OutputTimeUnit(TimeUnit.MILLISECONDS) @@ -130,7 +130,12 @@ public class MicroBenchmarkStreamTests { if (!instrumentation.toString().toLowerCase().contains("nosleuth")) { String b3 = message.getHeaders().get("b3", String.class); // System.out.println("Checking the b3 header [" + b3 + "]"); - assertThat(b3).startsWith("4883117762eb9420"); + assertThat(b3).isNotEmpty(); + if (b3.startsWith("0000000000000000")) { + assertThat(b3).startsWith("00000000000000004883117762eb9420"); + } else { + assertThat(b3).startsWith("4883117762eb9420"); + } } } diff --git a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/webflux/MicroBenchmarkHttpTests.java b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/webflux/MicroBenchmarkHttpTests.java index 3fcf02146..9f985a9ba 100644 --- a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/webflux/MicroBenchmarkHttpTests.java +++ b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/webflux/MicroBenchmarkHttpTests.java @@ -43,7 +43,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.web.reactive.server.WebTestClient; @Measurement(iterations = 5, time = 1) -@Warmup(iterations = 10, time = 1) +@Warmup(iterations = 5, time = 1) @Fork(2) @BenchmarkMode(Mode.SampleTime) @OutputTimeUnit(TimeUnit.MILLISECONDS) diff --git a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/webflux/SpringWebFluxBenchmarksTests.java b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/webflux/SpringWebFluxBenchmarksTests.java index f70ce2546..b7c7719af 100644 --- a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/webflux/SpringWebFluxBenchmarksTests.java +++ b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/webflux/SpringWebFluxBenchmarksTests.java @@ -56,14 +56,14 @@ import org.springframework.cloud.sleuth.benchmarks.jmh.TracerImplementation; import org.springframework.context.ConfigurableApplicationContext; @Measurement(iterations = 5, time = 1) -@Warmup(iterations = 10, time = 1) +@Warmup(iterations = 5, time = 1) @Fork(2) @BenchmarkMode(Mode.SampleTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) @Threads(2) @State(Scope.Benchmark) @Microbenchmark -public class SpringWebFluxBenchmarksTests { +public abstract class SpringWebFluxBenchmarksTests { static final SpanHandler FAKE_SPAN_HANDLER = new SpanHandler() { // intentionally anonymous to prevent logging fallback on NOOP diff --git a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/instrument/reactor/SleuthReactorProperties.java b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/instrument/reactor/SleuthReactorProperties.java index 8d22b5175..5cbf100e8 100644 --- a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/instrument/reactor/SleuthReactorProperties.java +++ b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/instrument/reactor/SleuthReactorProperties.java @@ -88,12 +88,16 @@ public class SleuthReactorProperties { /** * Wraps each operator in a Sleuth representation. + * @deprecated to be removed in Sleuth 4.0.0 */ + @Deprecated DECORATE_ON_EACH, /** * Wraps only the last operator in Sleuth representation. + * @deprecated to be removed in Sleuth 4.0.0 */ + @Deprecated DECORATE_ON_LAST, /**