Fixed benchmarks

This commit is contained in:
Marcin Grzejszczak
2020-11-26 10:40:46 +01:00
parent c9593b840a
commit f8245ac769
10 changed files with 50 additions and 27 deletions

View File

@@ -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<byte[]> 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<String, String> 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<String>, Flux<String>> 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<String>, Message<String>> 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<String>, Message<String>> 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<Message<String>>, Flux<Message<String>>> 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<String, String> 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<String>, Flux<String>> 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<String>, Flux<String>> onLastFunction() {
System.out.println("on last function");
log.info("on last function");
return new SleuthFunction();
}

View File

@@ -121,7 +121,11 @@ public class SleuthBenchmarkingSpringWebFluxApp implements ApplicationListener<R
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");
});
}
@@ -137,7 +141,11 @@ public class SleuthBenchmarkingSpringWebFluxApp implements ApplicationListener<R
WebFluxSleuthOperators.withSpanInScope(signal.getContext(), () -> 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");
});
}

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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");
}
}
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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,
/**