Updated benchmarks

This commit is contained in:
Marcin Grzejszczak
2021-02-26 09:38:44 +01:00
parent 985e669f02
commit b398ae6be3
4 changed files with 81 additions and 52 deletions

View File

@@ -135,6 +135,14 @@ public class SleuthBenchmarkingStreamApplication {
return new SleuthFunction();
}
@Bean(name = "myFlux")
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "DECORATE_QUEUES",
matchIfMissing = true)
public Function<Flux<String>, Flux<String>> decorateQueuesFunction() {
log.info("decorate queues function");
return new SleuthFunction();
}
@Bean(name = "myFlux")
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "DECORATE_ON_LAST")
public Function<Flux<String>, Flux<String>> onLastFunction() {

View File

@@ -16,6 +16,8 @@
package org.springframework.cloud.sleuth.benchmarks.jmh;
import org.springframework.cloud.sleuth.autoconfig.instrument.reactor.SleuthReactorProperties;
public class Pair {
final String key;
final String value;
@@ -33,19 +35,19 @@ public class Pair {
return new Pair(key, value);
}
public static Pair noHook() {
return new Pair("spring.sleuth.reactor.decorate-hooks", "false");
}
public static Pair noSleuth() {
return new Pair("spring.sleuth.enabled", "false");
}
public static Pair onEach() {
return new Pair("spring.sleuth.reactor.decorate-on-each", "true");
return new Pair("spring.sleuth.reactor.instrumentation-type", SleuthReactorProperties.InstrumentationType.DECORATE_ON_EACH.name());
}
public static Pair manual() {
return new Pair("spring.sleuth.reactor.instrumentation-type", SleuthReactorProperties.InstrumentationType.MANUAL.name());
}
public static Pair onLast() {
return new Pair("spring.sleuth.reactor.decorate-on-each", "false");
return new Pair("spring.sleuth.reactor.instrumentation-type", SleuthReactorProperties.InstrumentationType.DECORATE_ON_LAST.name());
}
}

View File

@@ -18,9 +18,7 @@ package org.springframework.cloud.sleuth.benchmarks.jmh.stream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -44,6 +42,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.sleuth.benchmarks.app.stream.SleuthBenchmarkingStreamApplication;
import org.springframework.cloud.sleuth.benchmarks.jmh.Pair;
import org.springframework.cloud.sleuth.benchmarks.jmh.TracerImplementation;
import org.springframework.cloud.stream.binder.test.InputDestination;
import org.springframework.cloud.stream.binder.test.OutputDestination;
@@ -53,7 +52,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -110,7 +108,7 @@ public class MicroBenchmarkStreamTests {
strings.addAll(Arrays.asList("--spring.jmx.enabled=false",
"--spring.application.name=defaultTraceContextForStream" + instrumentation.name() + "_"
+ tracerImplementation.name()));
strings.addAll(instrumentation.entires.stream().map(s -> "--" + s).collect(Collectors.toList()));
strings.addAll(Arrays.asList(instrumentation.asParams()));
return strings.toArray(new String[0]);
}
@@ -155,30 +153,46 @@ public class MicroBenchmarkStreamTests {
public enum Instrumentation {
noSleuthSimple("spring.sleuth.enabled=false,spring.sleuth.function.type=simple"), sleuthSimple(
"spring.sleuth.function.type=simple"), sleuthSimpleWithAround(
"spring.sleuth.function.type=simple_function_with_around"), noSleuthReactiveSimple(
"spring.sleuth.enabled=false,spring.sleuth.function.type=reactive_simple"), sleuthReactiveSimpleManual(
"spring.sleuth.function.type=reactive_simple_manual"), sleuthReactiveSimpleOnEach(
"spring.sleuth.reactor.instrumentation-type=DECORATE_ON_EACH,spring.sleuth.integration.enabled=true,spring.sleuth.function.type=DECORATE_ON_EACH"),
// This won't work with messaging
// sleuthReactiveSimpleOnLast("spring.sleuth.reactor.instrumentation-type=DECORATE_ON_LAST,spring.sleuth.function.type=DECORATE_ON_LAST"),
// NO FUNCTION, NO INTEGRATION, MANUAL OPERATORS
sleuthSimpleManual(
"spring.sleuth.function.enabled=false,spring.sleuth.integration.enabled=false,spring.sleuth.function.type=simple_manual"), sleuthSimpleNoFunctionInstrumentationManual(
"spring.sleuth.function.type=simple_manual,spring.sleuth.function.enabled=false,spring.sleuth.integration.enabled=true,spring.sleuth.reactor.instrumentation-type=MANUAL"), sleuthReactiveSimpleNoFunctionInstrumentationManual(
"spring.sleuth.function.type=reactive_simple_manual,spring.sleuth.function.enabled=false,spring.sleuth.integration.enabled=true,spring.sleuth.reactor.instrumentation-type=MANUAL");
// @formatter:off
noSleuthSimple(Pair.noSleuth(), function("simple")),
sleuthSimpleOnQueues(function("simple")),
sleuthSimpleManual(function("simple_manual"), Pair.manual(), functionDisabled(), integrationDisabled()),
sleuthSimpleNoFunctionInstrumentationManual(function("simple_manual"), Pair.manual(), functionDisabled(), integrationEnabled()),
sleuthSimpleOnEach(function("simple"), Pair.onEach()),
sleuthSimpleOnLast(function("simple"), Pair.onLast()),
sleuthSimpleWithAroundOnQueues(function("simple_function_with_around")),
noSleuthReactiveSimple(function("reactive_simple"), Pair.noSleuth()),
sleuthReactiveSimpleOnQueues(function("DECORATE_QUEUES")),
sleuthReactiveSimpleOnEach(function("DECORATE_ON_EACH"), Pair.onEach(), integrationEnabled()),
sleuthReactiveSimpleManual(function("reactive_simple_manual"), Pair.manual()),
sleuthReactiveSimpleNoFunctionInstrumentationManual(function("reactive_simple_manual"), Pair.manual(), integrationEnabled(), functionDisabled());
// @formatter:on
private Set<String> entires = new HashSet<>();
private final List<Pair> pairs;
Instrumentation(String key, String value) {
this.entires.add(key + "=" + value);
Instrumentation(Pair... pairs) {
this.pairs = Arrays.asList(pairs);
}
Instrumentation(String commaSeparated) {
this.entires.addAll(StringUtils.commaDelimitedListToSet(commaSeparated));
String[] asParams() {
return this.pairs.stream().map(p -> "--" + p.asProp()).toArray(String[]::new);
}
static Pair function(String type) {
return Pair.of("spring.sleuth.function.type", type);
}
static Pair integrationEnabled() {
return Pair.of("spring.sleuth.integration.enabled", "true");
}
static Pair integrationDisabled() {
return Pair.of("spring.sleuth.integration.enabled", "false");
}
static Pair functionDisabled() {
return Pair.of("spring.sleuth.function.enabled", "false");
}
}
}

View File

@@ -16,7 +16,11 @@
package org.springframework.cloud.sleuth.benchmarks.jmh.webflux;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import brave.Tracing;
import jmh.mbr.junit5.Microbenchmark;
@@ -38,6 +42,7 @@ 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.cloud.sleuth.benchmarks.jmh.Pair;
import org.springframework.cloud.sleuth.benchmarks.jmh.TracerImplementation;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.web.reactive.server.WebTestClient;
@@ -82,10 +87,12 @@ public class MicroBenchmarkHttpTests {
}
protected String[] runArgs() {
return new String[] { "--spring.jmx.enabled=false",
String[] defaultArgs = new String[] { "--spring.jmx.enabled=false",
"--spring.application.name=defaultTraceContext" + instrumentation.name() + "_"
+ tracerImplementation.name(),
"--" + instrumentation.key + "=" + instrumentation.value };
+ tracerImplementation.name() };
List<String> list = new ArrayList<>(Arrays.asList(defaultArgs));
list.addAll(Arrays.asList(instrumentation.asParams()));
return list.toArray(new String[0]);
}
void run() {
@@ -109,33 +116,31 @@ public class MicroBenchmarkHttpTests {
public enum Instrumentation {
noSleuthSimple("spring.sleuth.enabled", "false", "/simple"), sleuthSimpleManual(
"spring.sleuth.reactor.instrumentation-type", "MANUAL",
"/simple"), sleuthManual("spring.sleuth.reactor.instrumentation-type", "MANUAL",
"/simpleManual"), sleuthSimpleOnEach("spring.sleuth.reactor.instrumentation-type",
"DECORATE_ON_EACH",
"/simple"), sleuthSimpleOnLast("spring.sleuth.reactor.instrumentation-type",
"DECORATE_ON_LAST", "/simple"), noSleuthComplex("spring.sleuth.enabled",
"false", "/complexNoSleuth"), onEachComplex(
"spring.sleuth.reactor.instrumentation-type",
"DECORATE_ON_EACH", "/complex"), onLastComplex(
"spring.sleuth.reactor.instrumentation-type",
"DECORATE_ON_LAST", "/complex"), onManualComplex(
"spring.sleuth.reactor.instrumentation-type",
"MANUAL", "/complexManual");
private String key;
private String value;
// @formatter:off
noSleuthSimple("/simple", Pair.noSleuth()),
sleuthSimpleOnHooks("/simple"),
sleuthSimpleManual("/simpleManual", Pair.manual()),
sleuthSimpleOnEach("/simple", Pair.onEach()),
sleuthSimpleOnLast("/simple", Pair.onLast()),
noSleuthComplex("/complexNoSleuth", Pair.noSleuth()),
onHooksComplex("/complex"),
onManualComplex("/complexManual", Pair.manual()),
onEachComplex("/complex", Pair.onEach()),
onLastComplex("/complex", Pair.onLast());
// @formatter:on
private String url;
Instrumentation(String key, String value, String url) {
this.key = key;
this.value = value;
private List<Pair> pairs;
Instrumentation(String url, Pair... pairs) {
this.url = url;
this.pairs = Arrays.asList(pairs);
}
String[] asParams() {
return this.pairs.stream().map(p -> "--" + p.asProp()).collect(Collectors.toList()).toArray(new String[0]);
}
}
}