-
Notifications
You must be signed in to change notification settings - Fork 332
Skip synchronized(unsafeTags) on owner-thread tag writes #11082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bm1549
wants to merge
5
commits into
master
Choose a base branch
from
brian.marks/thread-owned-tags
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7b8dee3
Skip synchronized(unsafeTags) on owner-thread tag writes
bm1549 d664ab2
Add cross-thread stress tests and fix benchmark setup race
bm1549 d992fcd
Move thread-ownership optimization into OptimizedTagMap
bm1549 33c13e8
Rework thread-owned tags: encapsulate locking via withLock API
bm1549 8d5c038
Fix SpotBugs: suppress AT_NONATOMIC warnings for owner-thread fast path
bm1549 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
161 changes: 161 additions & 0 deletions
161
dd-trace-core/src/jmh/java/datadog/trace/core/SpanTagBenchmark.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| package datadog.trace.core; | ||
|
|
||
| import static java.util.concurrent.TimeUnit.MICROSECONDS; | ||
| import static java.util.concurrent.TimeUnit.NANOSECONDS; | ||
|
|
||
| import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Fork; | ||
| import org.openjdk.jmh.annotations.Level; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.Threads; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
|
|
||
| @BenchmarkMode(Mode.Throughput) | ||
| @Warmup(iterations = 5) | ||
| @Measurement(iterations = 5) | ||
| @Fork(2) | ||
| public class SpanTagBenchmark { | ||
|
|
||
| static final CoreTracer TRACER = CoreTracer.builder().build(); | ||
|
|
||
| @State(Scope.Thread) | ||
| public static class SpanPerThread { | ||
| AgentSpan span; | ||
|
|
||
| @Setup(Level.Invocation) | ||
| public void setup() { | ||
| span = TRACER.startSpan("benchmark", "tag-benchmark"); | ||
| } | ||
| } | ||
|
|
||
| @State(Scope.Benchmark) | ||
| public static class SharedSpan { | ||
| AgentSpan span; | ||
|
|
||
| @Setup(Level.Iteration) | ||
| public void setup() { | ||
| span = TRACER.startSpan("benchmark", "tag-benchmark-shared"); | ||
| } | ||
| } | ||
|
|
||
| @Benchmark | ||
| @Threads(1) | ||
| @OutputTimeUnit(NANOSECONDS) | ||
| public AgentSpan setStringTag_ownerThread(SpanPerThread state) { | ||
| state.span.setTag("key", "value"); | ||
| return state.span; | ||
| } | ||
|
|
||
| @Benchmark | ||
| @Threads(1) | ||
| @OutputTimeUnit(NANOSECONDS) | ||
| public AgentSpan setIntTag_ownerThread(SpanPerThread state) { | ||
| state.span.setTag("key", 42); | ||
| return state.span; | ||
| } | ||
|
|
||
| @Benchmark | ||
| @Threads(1) | ||
| @OutputTimeUnit(NANOSECONDS) | ||
| public AgentSpan setTenTags_ownerThread(SpanPerThread state) { | ||
| state.span.setTag("k0", "v0"); | ||
| state.span.setTag("k1", "v1"); | ||
| state.span.setTag("k2", "v2"); | ||
| state.span.setTag("k3", "v3"); | ||
| state.span.setTag("k4", "v4"); | ||
| state.span.setTag("k5", 5); | ||
| state.span.setTag("k6", 6L); | ||
| state.span.setTag("k7", 7.0); | ||
| state.span.setTag("k8", true); | ||
| state.span.setTag("k9", "v9"); | ||
| return state.span; | ||
| } | ||
|
|
||
| @Benchmark | ||
| @Threads(8) | ||
| @OutputTimeUnit(NANOSECONDS) | ||
| public AgentSpan setStringTag_crossThread(SharedSpan state) { | ||
| state.span.setTag("key", "value"); | ||
| return state.span; | ||
| } | ||
|
|
||
| // Multi-threaded owner-thread benchmarks: 8 threads each working on their own span. | ||
| // Measures the macro impact of the optimization when many threads tag spans concurrently, | ||
| // the realistic web-server scenario. | ||
|
|
||
| @Benchmark | ||
| @Threads(8) | ||
| @OutputTimeUnit(NANOSECONDS) | ||
| public AgentSpan setStringTag_ownerThread_8T(SpanPerThread state) { | ||
| state.span.setTag("key", "value"); | ||
| return state.span; | ||
| } | ||
|
|
||
| @Benchmark | ||
| @Threads(8) | ||
| @OutputTimeUnit(NANOSECONDS) | ||
| public AgentSpan setIntTag_ownerThread_8T(SpanPerThread state) { | ||
| state.span.setTag("key", 42); | ||
| return state.span; | ||
| } | ||
|
|
||
| @Benchmark | ||
| @Threads(8) | ||
| @OutputTimeUnit(NANOSECONDS) | ||
| public AgentSpan setTenTags_ownerThread_8T(SpanPerThread state) { | ||
| state.span.setTag("k0", "v0"); | ||
| state.span.setTag("k1", "v1"); | ||
| state.span.setTag("k2", "v2"); | ||
| state.span.setTag("k3", "v3"); | ||
| state.span.setTag("k4", "v4"); | ||
| state.span.setTag("k5", 5); | ||
| state.span.setTag("k6", 6L); | ||
| state.span.setTag("k7", 7.0); | ||
| state.span.setTag("k8", true); | ||
| state.span.setTag("k9", "v9"); | ||
| return state.span; | ||
| } | ||
|
|
||
| @Benchmark | ||
| @Threads(1) | ||
| @OutputTimeUnit(MICROSECONDS) | ||
| public AgentSpan fullLifecycle_tenTags(SpanPerThread state) { | ||
| state.span.setTag("k0", "v0"); | ||
| state.span.setTag("k1", "v1"); | ||
| state.span.setTag("k2", "v2"); | ||
| state.span.setTag("k3", "v3"); | ||
| state.span.setTag("k4", "v4"); | ||
| state.span.setTag("k5", 5); | ||
| state.span.setTag("k6", 6L); | ||
| state.span.setTag("k7", 7.0); | ||
| state.span.setTag("k8", true); | ||
| state.span.setTag("k9", "v9"); | ||
| state.span.finish(); | ||
| return state.span; | ||
| } | ||
|
|
||
| @Benchmark | ||
| @Threads(8) | ||
| @OutputTimeUnit(MICROSECONDS) | ||
| public AgentSpan fullLifecycle_tenTags_8T(SpanPerThread state) { | ||
| state.span.setTag("k0", "v0"); | ||
| state.span.setTag("k1", "v1"); | ||
| state.span.setTag("k2", "v2"); | ||
| state.span.setTag("k3", "v3"); | ||
| state.span.setTag("k4", "v4"); | ||
| state.span.setTag("k5", 5); | ||
| state.span.setTag("k6", 6L); | ||
| state.span.setTag("k7", 7.0); | ||
| state.span.setTag("k8", true); | ||
| state.span.setTag("k9", "v9"); | ||
| state.span.finish(); | ||
| return state.span; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.