Skip to content

Commit f8245ac

Browse files
Fixed benchmarks
1 parent c9593b8 commit f8245ac

File tree

10 files changed

+50
-27
lines changed

10 files changed

+50
-27
lines changed

benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/stream/SleuthBenchmarkingStreamApplication.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
@Import(TestChannelBinderConfiguration.class)
5151
public class SleuthBenchmarkingStreamApplication {
5252

53+
private static final Logger log = LoggerFactory.getLogger(SleuthBenchmarkingStreamApplication.class);
54+
5355
public static void main(String[] args) throws InterruptedException, IOException {
5456
// System.setProperty("spring.sleuth.enabled", "false");
5557
// System.setProperty("spring.sleuth.reactor.instrumentation-type",
@@ -64,16 +66,16 @@ public static void main(String[] args) throws InterruptedException, IOException
6466
InputDestination input = context.getBean(InputDestination.class);
6567
input.send(MessageBuilder.withPayload("hello".getBytes())
6668
.setHeader("b3", "4883117762eb9420-4883117762eb9420-1").build());
67-
System.out.println("Retrieving the message for tests");
69+
log.info("Retrieving the message for tests");
6870
OutputDestination output = context.getBean(OutputDestination.class);
6971
Message<byte[]> message = output.receive(200L);
70-
System.out.println("Got the message from output");
72+
log.info("Got the message from output");
7173
assertThat(message).isNotNull();
72-
System.out.println("Message is not null");
74+
log.info("Message is not null");
7375
assertThat(message.getPayload()).isEqualTo("HELLO".getBytes());
74-
System.out.println("Payload is HELLO");
76+
log.info("Payload is HELLO");
7577
String b3 = message.getHeaders().get("b3", String.class);
76-
System.out.println("Checking the b3 header [" + b3 + "]");
78+
log.info("Checking the b3 header [" + b3 + "]");
7779
assertThat(b3).startsWith("4883117762eb9420");
7880
}
7981
}
@@ -86,57 +88,57 @@ ExecutorService sleuthExecutorService() {
8688
@Bean(name = "myFlux")
8789
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "simple")
8890
public Function<String, String> simple() {
89-
System.out.println("simple_function");
91+
log.info("simple_function");
9092
return new SimpleFunction();
9193
}
9294

9395
@Bean(name = "myFlux")
9496
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "reactive_simple")
9597
public Function<Flux<String>, Flux<String>> reactiveSimple() {
96-
System.out.println("simple_reactive_function");
98+
log.info("simple_reactive_function");
9799
return new SimpleReactiveFunction();
98100
}
99101

100102
@Bean(name = "myFlux")
101103
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "simple_function_with_around")
102104
public Function<Message<String>, Message<String>> simpleFunctionWithAround() {
103-
System.out.println("simple_function_with_around");
105+
log.info("simple_function_with_around");
104106
return new SimpleMessageFunction();
105107
}
106108

107109
@Bean(name = "myFlux")
108110
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "simple_manual")
109111
public Function<Message<String>, Message<String>> simpleManual(BeanFactory beanFactory) {
110-
System.out.println("simple_manual_function");
112+
log.info("simple_manual_function");
111113
return new SimpleManualFunction(beanFactory);
112114
}
113115

114116
@Bean(name = "myFlux")
115117
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "reactive_simple_manual")
116118
public Function<Flux<Message<String>>, Flux<Message<String>>> reactiveSimpleManual(BeanFactory beanFactory) {
117-
System.out.println("simple_reactive_manual_function");
119+
log.info("simple_reactive_manual_function");
118120
return new SimpleReactiveManualFunction(beanFactory);
119121
}
120122

121123
@Bean(name = "myFlux")
122124
@ConditionalOnProperty(value = "spring.sleuth.nonreactive.function.enabled", havingValue = "true")
123125
public Function<String, String> nonReactiveFunction(ExecutorService executorService) {
124-
System.out.println("no sleuth non reactive function");
126+
log.info("no sleuth non reactive function");
125127
return new SleuthNonReactiveFunction(executorService);
126128
}
127129

128130
@Bean(name = "myFlux")
129131
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "DECORATE_ON_EACH",
130132
matchIfMissing = true)
131133
public Function<Flux<String>, Flux<String>> onEachFunction() {
132-
System.out.println("on each function");
134+
log.info("on each function");
133135
return new SleuthFunction();
134136
}
135137

136138
@Bean(name = "myFlux")
137139
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "DECORATE_ON_LAST")
138140
public Function<Flux<String>, Flux<String>> onLastFunction() {
139-
System.out.println("on last function");
141+
log.info("on last function");
140142
return new SleuthFunction();
141143
}
142144

benchmarks/src/main/java/org/springframework/cloud/sleuth/benchmarks/app/webflux/SleuthBenchmarkingSpringWebFluxApp.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ public Mono<String> complex() {
121121
log.info("Doing assertions");
122122
TraceContext traceContext = signal.getContext().get(TraceContext.class);
123123
Assert.notNull(traceContext, "Context must be set by Sleuth instrumentation");
124-
Assert.state(traceContext.traceId().equals("4883117762eb9420"), "TraceId must be propagated");
124+
if (traceContext.traceId().startsWith("0000000000000000")) {
125+
Assert.state(traceContext.traceId().equals("00000000000000004883117762eb9420"), "TraceId must be propagated");
126+
} else {
127+
Assert.state(traceContext.traceId().equals("4883117762eb9420"), "TraceId must be propagated");
128+
}
125129
log.info("Assertions passed");
126130
});
127131
}
@@ -137,7 +141,11 @@ public Mono<String> complexManual() {
137141
WebFluxSleuthOperators.withSpanInScope(signal.getContext(), () -> log.info("Doing assertions"));
138142
TraceContext traceContext = signal.getContext().get(TraceContext.class);
139143
Assert.notNull(traceContext, "Context must be set by Sleuth instrumentation");
140-
Assert.state(traceContext.traceId().equals("4883117762eb9420"), "TraceId must be propagated");
144+
if (traceContext.traceId().startsWith("0000000000000000")) {
145+
Assert.state(traceContext.traceId().equals("00000000000000004883117762eb9420"), "TraceId must be propagated");
146+
} else {
147+
Assert.state(traceContext.traceId().equals("4883117762eb9420"), "TraceId must be propagated");
148+
}
141149
log.info("Assertions passed");
142150
});
143151
}

benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/bridge/BridgeTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
package org.springframework.cloud.sleuth.benchmarks.jmh.bridge;
1818

19+
import java.util.concurrent.TimeUnit;
20+
1921
import jmh.mbr.junit5.Microbenchmark;
2022
import org.openjdk.jmh.annotations.Benchmark;
2123
import org.openjdk.jmh.annotations.BenchmarkMode;
2224
import org.openjdk.jmh.annotations.Fork;
2325
import org.openjdk.jmh.annotations.Measurement;
2426
import org.openjdk.jmh.annotations.Mode;
27+
import org.openjdk.jmh.annotations.OutputTimeUnit;
2528
import org.openjdk.jmh.annotations.Param;
2629
import org.openjdk.jmh.annotations.Scope;
2730
import org.openjdk.jmh.annotations.Setup;
@@ -42,10 +45,11 @@
4245

4346
import static org.assertj.core.api.BDDAssertions.then;
4447

45-
@Measurement(iterations = 5)
46-
@Warmup(iterations = 1)
47-
@Fork(value = 2, warmups = 0)
48-
@BenchmarkMode(Mode.AverageTime)
48+
@Measurement(iterations = 5, time = 1)
49+
@Warmup(iterations = 5, time = 1)
50+
@Fork(2)
51+
@BenchmarkMode(Mode.SampleTime)
52+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
4953
@Microbenchmark
5054
public class BridgeTests {
5155

benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/AnnotationBenchmarksTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import static org.assertj.core.api.BDDAssertions.then;
4242

4343
@Measurement(iterations = 5, time = 1)
44-
@Warmup(iterations = 10, time = 1)
44+
@Warmup(iterations = 5, time = 1)
4545
@Fork(2)
4646
@BenchmarkMode(Mode.SampleTime)
4747
@OutputTimeUnit(TimeUnit.MICROSECONDS)

benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/AsyncBenchmarksTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import static org.assertj.core.api.BDDAssertions.then;
4242

4343
@Measurement(iterations = 5, time = 1)
44-
@Warmup(iterations = 10, time = 1)
44+
@Warmup(iterations = 5, time = 1)
4545
@Fork(2)
4646
@BenchmarkMode(Mode.SampleTime)
4747
@OutputTimeUnit(TimeUnit.MICROSECONDS)

benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/mvc/RestTemplateBenchmarkTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* We're checking how much overhead does the instrumentation of the RestTemplate take
5454
*/
5555
@Measurement(iterations = 5, time = 1)
56-
@Warmup(iterations = 10, time = 1)
56+
@Warmup(iterations = 5, time = 1)
5757
@Fork(2)
5858
@BenchmarkMode(Mode.SampleTime)
5959
@OutputTimeUnit(TimeUnit.MICROSECONDS)

benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/stream/MicroBenchmarkStreamTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
import static org.assertj.core.api.Assertions.assertThat;
5959

6060
@Measurement(iterations = 5, time = 1)
61-
@Warmup(iterations = 10, time = 1)
61+
@Warmup(iterations = 5, time = 1)
6262
@Fork(2)
6363
@BenchmarkMode(Mode.SampleTime)
6464
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@@ -130,7 +130,12 @@ private void assertThatOutputMessageGotReceived() {
130130
if (!instrumentation.toString().toLowerCase().contains("nosleuth")) {
131131
String b3 = message.getHeaders().get("b3", String.class);
132132
// System.out.println("Checking the b3 header [" + b3 + "]");
133-
assertThat(b3).startsWith("4883117762eb9420");
133+
assertThat(b3).isNotEmpty();
134+
if (b3.startsWith("0000000000000000")) {
135+
assertThat(b3).startsWith("00000000000000004883117762eb9420");
136+
} else {
137+
assertThat(b3).startsWith("4883117762eb9420");
138+
}
134139
}
135140
}
136141

benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/webflux/MicroBenchmarkHttpTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.springframework.test.web.reactive.server.WebTestClient;
4444

4545
@Measurement(iterations = 5, time = 1)
46-
@Warmup(iterations = 10, time = 1)
46+
@Warmup(iterations = 5, time = 1)
4747
@Fork(2)
4848
@BenchmarkMode(Mode.SampleTime)
4949
@OutputTimeUnit(TimeUnit.MILLISECONDS)

benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/webflux/SpringWebFluxBenchmarksTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@
5656
import org.springframework.context.ConfigurableApplicationContext;
5757

5858
@Measurement(iterations = 5, time = 1)
59-
@Warmup(iterations = 10, time = 1)
59+
@Warmup(iterations = 5, time = 1)
6060
@Fork(2)
6161
@BenchmarkMode(Mode.SampleTime)
6262
@OutputTimeUnit(TimeUnit.MICROSECONDS)
6363
@Threads(2)
6464
@State(Scope.Benchmark)
6565
@Microbenchmark
66-
public class SpringWebFluxBenchmarksTests {
66+
public abstract class SpringWebFluxBenchmarksTests {
6767

6868
static final SpanHandler FAKE_SPAN_HANDLER = new SpanHandler() {
6969
// intentionally anonymous to prevent logging fallback on NOOP

spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/instrument/reactor/SleuthReactorProperties.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,16 @@ public enum InstrumentationType {
8888

8989
/**
9090
* Wraps each operator in a Sleuth representation.
91+
* @deprecated to be removed in Sleuth 4.0.0
9192
*/
93+
@Deprecated
9294
DECORATE_ON_EACH,
9395

9496
/**
9597
* Wraps only the last operator in Sleuth representation.
98+
* @deprecated to be removed in Sleuth 4.0.0
9699
*/
100+
@Deprecated
97101
DECORATE_ON_LAST,
98102

99103
/**

0 commit comments

Comments
 (0)