-
Notifications
You must be signed in to change notification settings - Fork 323
Replace jctools NonBlockingHashMap with ConcurrentHashMap #9700
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package datadog.trace.common; | ||
|
|
||
| import static java.util.concurrent.TimeUnit.MICROSECONDS; | ||
| import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
|
||
| import de.thetaphi.forbiddenapis.SuppressForbidden; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import org.jctools.maps.NonBlockingHashMap; | ||
| 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; | ||
| import org.openjdk.jmh.infra.Blackhole; | ||
|
|
||
| /* | ||
| JDK 1.8 | ||
| Benchmark Mode Cnt Score Error Units | ||
| NonBlockingHashMapBenchmark.benchConcurrentHashMap avgt 1.153 us/op | ||
| NonBlockingHashMapBenchmark.benchNonBlockingHashMap avgt 1.457 us/op | ||
| JDK 21 | ||
| Benchmark Mode Cnt Score Error Units | ||
| NonBlockingHashMapBenchmark.benchConcurrentHashMap avgt 1.088 us/op | ||
| NonBlockingHashMapBenchmark.benchNonBlockingHashMap avgt 1.278 us/op | ||
| */ | ||
| @State(Scope.Benchmark) | ||
| @Warmup(iterations = 1, time = 30, timeUnit = SECONDS) | ||
| @Measurement(iterations = 1, time = 30, timeUnit = SECONDS) | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(MICROSECONDS) | ||
| @Fork(value = 1) | ||
| @SuppressForbidden | ||
| public class NonBlockingHashMapBenchmark { | ||
| private NonBlockingHashMap nonBlockingHashMap; | ||
| private ConcurrentHashMap concurrentHashMap; | ||
|
|
||
| @Setup(Level.Iteration) | ||
| public void setup() { | ||
| nonBlockingHashMap = new NonBlockingHashMap(512); | ||
| concurrentHashMap = new ConcurrentHashMap(512); | ||
| for (int i = 0; i < 256; i++) { | ||
| nonBlockingHashMap.put("test" + i, "test"); | ||
| concurrentHashMap.put("test" + i, "test"); | ||
| } | ||
|
Comment on lines
+45
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about to test
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the key influencing the test?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, but it will mimic real usage I believe...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's not interesting in this case as we will measure the |
||
| } | ||
|
|
||
| @Benchmark | ||
| @Threads(Threads.MAX) | ||
| public void benchNonBlockingHashMap(Blackhole blackhole) { | ||
| nonBlockingHashMap.put("test", "test"); | ||
| blackhole.consume(nonBlockingHashMap.remove("test")); | ||
| } | ||
|
|
||
| @Benchmark | ||
| @Threads(Threads.MAX) | ||
| public void benchConcurrentHashMap(Blackhole blackhole) { | ||
| concurrentHashMap.put("test", "test"); | ||
| blackhole.consume(concurrentHashMap.remove("test")); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One key differentiator of
NonBlockingHashMapLongis it supports primitivelongkeys, whereasConcurrentHashMapwill box primitive keys intoLong.Could we add a benchmark comparing
NonBlockingHashMapLong<String>withConcurrentHashMap<Long, String>to see what effect that has? Note we should make sure we test long values outside of the cached range of -128 to 127There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Let me test the side effect of unboxing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also worth checking with profiling where the
getEventTypeNameMapmethod is used, because I can't find a caller in the current codebase. If it's not used then do we need to keep this map at all?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the put operation I don't think nothing will change since I see later on:
I cannot see any caller as well...let me ask around or dig more about this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I got confirmation that it's unused. Actually the whole package can be removed apparently. Now in this PR I limited to removing that map. I will open another PR to delete the package