Skip to content
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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

spkrka
Copy link
Member

@spkrka spkrka commented Jun 4, 2021

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

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 spkrka marked this pull request as draft June 4, 2021 11:53
}

ConcurrentDistribution(Supplier<Distribution> distributionSupplier) {
this(distributionSupplier, 4 * Runtime.getRuntime().availableProcessors());
Copy link
Member Author

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);
Copy link
Member Author

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);
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant