-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check scope existence lock free first (#110)
- Loading branch information
Showing
4 changed files
with
90 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
53 changes: 53 additions & 0 deletions
53
core/src/jmh/java/com/uber/m3/tally/ScopeImplConcurrent.java
This file contains 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,53 @@ | ||
package com.uber.m3.tally; | ||
|
||
import com.uber.m3.util.Duration; | ||
import com.uber.m3.util.ImmutableMap; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@Fork(value = 2, jvmArgsAppend = { "-server", "-XX:+UseG1GC" }) | ||
public class ScopeImplConcurrent { | ||
private static String KEYS[] = new String[]{ | ||
" ", "0", "@", "P", | ||
}; | ||
|
||
@Benchmark | ||
public void hotkeyLockContention(Blackhole bh, BenchmarkState state) { | ||
ImmutableMap<String, String> common = new ImmutableMap.Builder<String, String>().build(); | ||
for (int i = 0; i < 10000; i++) { | ||
|
||
for (String key : KEYS) { | ||
Scope scope = state.scope.computeSubscopeIfAbsent(key, common); | ||
assert scope != null; | ||
bh.consume(scope); | ||
} | ||
} | ||
} | ||
|
||
@State(org.openjdk.jmh.annotations.Scope.Benchmark) | ||
public static class BenchmarkState { | ||
|
||
private ScopeImpl scope; | ||
|
||
@Setup | ||
public void setup() { | ||
this.scope = | ||
(ScopeImpl) new RootScopeBuilder() | ||
.reporter(new TestStatsReporter()) | ||
.reportEvery(Duration.MAX_VALUE); | ||
|
||
for (String key : KEYS) { | ||
scope.computeSubscopeIfAbsent(key, new ImmutableMap.Builder<String, String>().build()); | ||
} | ||
} | ||
|
||
@TearDown | ||
public void teardown() { | ||
scope.close(); | ||
} | ||
} | ||
} |
This file contains 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