-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add concurrent proxy in front of SemanticMetricDistribution #111
base: master
Are you sure you want to change the base?
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
} | ||
|
||
ConcurrentDistribution(Supplier<Distribution> distributionSupplier) { | ||
this(distributionSupplier, 4 * Runtime.getRuntime().availableProcessors()); |
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.
Not sure what a good number of shards should be
} | ||
|
||
ConcurrentDistribution(Supplier<Distribution> distributionSupplier, int minShards) { | ||
final int numShards = nearestPowerOfTwo(minShards); |
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.
Power of two to avoid modulo operation later
|
||
@Override | ||
public void record(double val) { | ||
final int targetShard = ((int) Thread.currentThread().getId() & shardBitmask); |
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.
Not sure how evenly this will distribute load - thread ids are auto-incremented, so might possibly be ok in practice
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).