This repository was archived by the owner on Jan 14, 2026. It is now read-only.
Add concurrent proxy in front of SemanticMetricDistribution#111
Draft
Add concurrent proxy in front of SemanticMetricDistribution#111
Conversation
The concurrent version is slightly slower than the synchronized
during low contention (43 vs 48 ops/us), but scales better as
contention increases.
The concurrent version also uses more memory
(currently a factor of 4 * num cores).
Benchmark Mode Cnt Score Error Units
DistributionBenchmark.conc1 thrpt 5 43.945 ± 1.092 ops/us
DistributionBenchmark.conc2 thrpt 5 78.461 ± 3.776 ops/us
DistributionBenchmark.conc4 thrpt 5 100.641 ± 7.070 ops/us
DistributionBenchmark.conc8 thrpt 5 96.606 ± 1.941 ops/us
DistributionBenchmark.sync1 thrpt 5 48.235 ± 2.858 ops/us
DistributionBenchmark.sync2 thrpt 5 17.794 ± 0.757 ops/us
DistributionBenchmark.sync4 thrpt 5 13.528 ± 1.251 ops/us
DistributionBenchmark.sync8 thrpt 5 26.025 ± 5.570 ops/us
spkrka
commented
Jun 4, 2021
| } | ||
|
|
||
| ConcurrentDistribution(Supplier<Distribution> distributionSupplier) { | ||
| this(distributionSupplier, 4 * Runtime.getRuntime().availableProcessors()); |
Member
Author
There was a problem hiding this comment.
Not sure what a good number of shards should be
spkrka
commented
Jun 4, 2021
| } | ||
|
|
||
| ConcurrentDistribution(Supplier<Distribution> distributionSupplier, int minShards) { | ||
| final int numShards = nearestPowerOfTwo(minShards); |
Member
Author
There was a problem hiding this comment.
Power of two to avoid modulo operation later
spkrka
commented
Jun 4, 2021
|
|
||
| @Override | ||
| public void record(double val) { | ||
| final int targetShard = ((int) Thread.currentThread().getId() & shardBitmask); |
Member
Author
There was a problem hiding this comment.
Not sure how evenly this will distribute load - thread ids are auto-incremented, so might possibly be ok in practice
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The concurrent version is slightly slower than the synchronized
during low contention (43 vs 48 ops/us), but scales better as
contention increases.
The concurrent version also uses more memory
(currently a factor of 4 * num cores).