Skip to content

Commit 43e835a

Browse files
author
Carter Kozak
authored
Trace threadlocal entry is never removed, only nulled (#849)
Trace threadlocal entry is never removed, only nulled
1 parent 4036f14 commit 43e835a

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: improvement
2+
improvement:
3+
description: Trace threadlocal entry is never removed, only nulled
4+
links:
5+
- https://github.com/palantir/tracing-java/pull/849

tracing-benchmarks/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tasks.jmhCompileGeneratedClasses {
1616
}
1717

1818
dependencies {
19-
annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess'
19+
jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess'
2020
compileOnly 'org.openjdk.jmh:jmh-generator-annprocess'
2121
api 'org.immutables:value::annotations'
2222
api 'org.openjdk.jmh:jmh-core'

tracing-benchmarks/src/jmh/java/com/palantir/tracing/TracingBenchmark.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
@OutputTimeUnit(TimeUnit.NANOSECONDS)
4444
@Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS)
4545
@Measurement(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS)
46-
@Fork(1)
46+
@Fork(value = 1, jvmArgsAppend = "-Dlog4j2.garbagefreeThreadContextMap=true")
4747
@Threads(4)
4848
@SuppressWarnings({"checkstyle:hideutilityclassconstructor", "checkstyle:VisibilityModifier"})
4949
public class TracingBenchmark {
@@ -88,6 +88,12 @@ public static void nestedSpans() {
8888
nestedSpans.run();
8989
}
9090

91+
@Benchmark
92+
public static void traceWithSingleSpan() {
93+
Tracer.fastStartSpan("benchmark");
94+
Tracer.fastCompleteSpan();
95+
}
96+
9197
private static Runnable createNestedSpan(int depth) {
9298
if (depth <= 0) {
9399
return Runnables.doNothing();

tracing/src/main/java/com/palantir/tracing/Tracer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ private static Trace getOrCreateCurrentTrace() {
919919
@VisibleForTesting
920920
static void clearCurrentTrace() {
921921
logClearingTrace();
922-
currentTrace.remove();
922+
currentTrace.set(null);
923923
MDC.remove(Tracers.TRACE_ID_KEY);
924924
MDC.remove(Tracers.TRACE_SAMPLED_KEY);
925925
MDC.remove(Tracers.REQUEST_ID_KEY);

0 commit comments

Comments
 (0)