Skip to content

Commit

Permalink
better profiling instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Sep 26, 2024
1 parent b1b56fe commit 5458f1d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
arebac-neo4j/testdb
*.jfr
profile*.html
**/profile/

# Created by https://www.toptal.com/developers/gitignore/api/eclipse,java,maven
# Edit at https://www.toptal.com/developers/gitignore?templates=eclipse,java,maven
Expand Down
4 changes: 2 additions & 2 deletions arebac-neo4j/Benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ java -cp target/classes:target/test-classes:target/all-dependencies/*:target/are

In order to profile a specific benchmark using [`async-profiler`](https://github.com/async-profiler/async-profiler), first download and extract `async-profiler` and then use the following command (replace `/PATH/TO/async-profiler` with the path you extracted `async-profiler` to):
```java
java -cp target/classes:target/test-classes:target/all-dependencies/*:target/arebac-neo4j-0.0.1-SNAPSHOT.jar io.github.danthe1st.arebac.neo4j.tests.airbnb.AirbnbBenchmark.scenario1GetReviewsFromHostGPEval -f 1 -jvmArgs '-agentpath:/PATH/TO/async-profiler/lib/libasyncProfiler.so=start,event=cpu,file=profile.html'
java -cp target/classes:target/test-classes:target/all-dependencies/*:target/arebac-neo4j-0.0.1-SNAPSHOT.jar org.openjdk.jmh.Main AirbnbBenchmark.scenario1GetReviewsFromHostGPEvalWithoutWeaving -prof 'async:libPath=/PATH/TO/async-profiler/lib/libasyncProfiler.so;output=flamegraph;dir=profile' -f 2
```
This configures JMH to only use a single fork and attaches async-profiler to create a CPU flamegraph in a `profile.html` file. The above example runs the benchmarks specified in the `SOBenchmark` class.
This configures JMH to only use only two forks and attaches async-profiler to create a CPU flamegraph in a `profile.html` file. The above example runs the benchmarks specified in the `SOBenchmark` class.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@Warmup(iterations = 4, time = 3, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 4, time = 3, timeUnit = TimeUnit.SECONDS)
public class AirbnbBenchmark {

@Benchmark
public void scenario1GetReviewsFromHostGPEvalWithWeaving(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Expand All @@ -36,7 +36,7 @@ public void scenario1GetReviewsFromHostGPEvalWithWeaving(AirbnbState state, Blac
result.forEach(bh::consume);
}
}

@Benchmark
public void scenario1GetReviewsFromHostGPEvalWithoutWeaving(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Expand All @@ -45,7 +45,7 @@ public void scenario1GetReviewsFromHostGPEvalWithoutWeaving(AirbnbState state, B
result.forEach(bh::consume);
}
}

@Benchmark
public void scenario1GetReviewsFromHostNeo4J(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Expand All @@ -54,11 +54,11 @@ public void scenario1GetReviewsFromHostNeo4J(AirbnbState state, Blackhole bh) {
WHERE h.host_id="$hostId"
RETURN r1,r2
""", Map.of("hostId", state.hostPatternInfo.nextId()));

result.forEachRemaining(bh::consume);
}
}

@Benchmark
public void scenario1GetReviewsFromReviewerGPEvalWithWeaving(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Expand All @@ -67,7 +67,7 @@ public void scenario1GetReviewsFromReviewerGPEvalWithWeaving(AirbnbState state,
result.forEach(bh::consume);
}
}

@Benchmark
public void scenario1GetReviewsFromReviewerGPEvalWithoutWeaving(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Expand All @@ -76,7 +76,7 @@ public void scenario1GetReviewsFromReviewerGPEvalWithoutWeaving(AirbnbState stat
result.forEach(bh::consume);
}
}

@Benchmark
public void scenario1GetReviewsFromReviewerNeo4J(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Expand All @@ -85,11 +85,11 @@ public void scenario1GetReviewsFromReviewerNeo4J(AirbnbState state, Blackhole bh
WHERE r.reviewer_id="REVIEWER_ID"
RETURN r
""", Map.of("hostId", state.reviewerPatternInfo.nextId()));

result.forEachRemaining(bh::consume);
}
}

@Benchmark
public void scenario2GPEvalWithWeaving(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Expand All @@ -98,7 +98,7 @@ public void scenario2GPEvalWithWeaving(AirbnbState state, Blackhole bh) {
result.forEach(bh::consume);
}
}

@Benchmark
public void scenario2GPEvalWithoutWeaving(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Expand All @@ -107,7 +107,7 @@ public void scenario2GPEvalWithoutWeaving(AirbnbState state, Blackhole bh) {
result.forEach(bh::consume);
}
}

@Benchmark
public void scenario2Neo4J(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Expand All @@ -117,18 +117,18 @@ public void scenario2Neo4J(AirbnbState state, Blackhole bh) {
WHERE h.host_id = $hostId AND n.neighborhood_id = $neighborhoodId
RETURN l
""", Map.of("hostId", id.subjectId(), "neighborhoodId", id.neighborhoodId()));

result.forEachRemaining(bh::consume);
}
}

@State(Scope.Thread)
public static class AirbnbState {
private final GraphDatabaseService database;
private final PatternInfo<String> hostPatternInfo;
private final PatternInfo<String> reviewerPatternInfo;
private final PatternInfo<Scenario2Id> scenario2PatternInfo;

public AirbnbState() {
try{
database = AirbnbSetup.getDatabase();
Expand All @@ -139,23 +139,23 @@ public AirbnbState() {
throw new RuntimeException("cannot initialize benchmark state", e);
}
}

public PatternInfo<String> getHostPatternInfo() {
return hostPatternInfo;
}

public PatternInfo<String> getReviewerPatternInfo() {
return reviewerPatternInfo;
}

}

private static class PatternInfo<T> {
private final List<T> ids;
private final Function<T, GraphPattern> patternGenerator;
private final List<GraphPattern> patterns;
private int currentIndex = 0;

public PatternInfo(List<T> ids, Function<T, GraphPattern> patternGenerator) {
this.ids = ids;
this.patternGenerator = patternGenerator;
Expand All @@ -165,27 +165,27 @@ public PatternInfo(List<T> ids, Function<T, GraphPattern> patternGenerator) {
}
this.patterns = List.copyOf(patterns);
}

public GraphPattern nextLoadedPattern() {
return patterns.get(nextIndex());
}

public GraphPattern computeNextPattern() {
return patternGenerator.apply(nextId());
}

public T nextId() {
return ids.get(nextIndex());
}

private int nextIndex() {
int index = currentIndex;
currentIndex = (currentIndex + 1) % ids.size();
return index;
}
}

private record Scenario2Id(String subjectId, String neighborhoodId) {

}
}

0 comments on commit 5458f1d

Please sign in to comment.