Skip to content

Commit

Permalink
additional benchmarks without weaving
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Sep 26, 2024
1 parent ac86af3 commit ba5be1f
Showing 1 changed file with 65 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import io.github.danthe1st.arebac.data.graph_pattern.GraphPattern;
import io.github.danthe1st.arebac.gpeval.GPEval;
Expand All @@ -27,10 +29,19 @@
public class AirbnbBenchmark {

@Benchmark
public void scenario1GetReviewsFromHostGPEval(AirbnbState state, Blackhole bh) {
public void scenario1GetReviewsFromHostGPEvalWithWeaving(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Neo4jDB db = new Neo4jDB(tx);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.nextHostPattern());
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.hostPatternInfo.computeNextPattern());
result.forEach(bh::consume);
}
}

@Benchmark
public void scenario1GetReviewsFromHostGPEvalWithoutWeaving(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Neo4jDB db = new Neo4jDB(tx);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.hostPatternInfo.nextLoadedPattern());
result.forEach(bh::consume);
}
}
Expand All @@ -42,17 +53,26 @@ public void scenario1GetReviewsFromHostNeo4J(AirbnbState state, Blackhole bh) {
MATCH (r1:Reviewer)-[: WROTE]->(r2:Review) -[: REVIEWS]->(l: Listing)<-[HOSTS]-(h: Host)
WHERE h.host_id="$hostId"
RETURN r1,r2
""", Map.of("hostId", state.nextHostId()));
""", Map.of("hostId", state.hostPatternInfo.nextId()));

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

@Benchmark
public void scenario1GetReviewsFromReviewerGPEval(AirbnbState state, Blackhole bh) {
public void scenario1GetReviewsFromReviewerGPEvalWithWeaving(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Neo4jDB db = new Neo4jDB(tx);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.nextReviewerPattern());
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.reviewerPatternInfo.computeNextPattern());
result.forEach(bh::consume);
}
}

@Benchmark
public void scenario1GetReviewsFromReviewerGPEvalWithoutWeaving(AirbnbState state, Blackhole bh) {
try(Transaction tx = state.database.beginTx()){
Neo4jDB db = new Neo4jDB(tx);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.reviewerPatternInfo.nextLoadedPattern());
result.forEach(bh::consume);
}
}
Expand All @@ -64,7 +84,7 @@ public void scenario1GetReviewsFromReviewerNeo4J(AirbnbState state, Blackhole bh
MATCH (r:Reviewer) -[: WROTE]-> (r2: Review)
WHERE r.reviewer_id="REVIEWER_ID"
RETURN r
""", Map.of("hostId", state.nextReviewerId()));
""", Map.of("hostId", state.reviewerPatternInfo.nextId()));

result.forEachRemaining(bh::consume);
}
Expand All @@ -73,38 +93,61 @@ public void scenario1GetReviewsFromReviewerNeo4J(AirbnbState state, Blackhole bh
@State(Scope.Thread)
public static class AirbnbState {
private final GraphDatabaseService database;
private final List<String> hostIds = List.of("131304391", "155715332", "404944621");
private int currentHostIndex = 0;
private final List<String> reviewerIds = List.of("272671293", "227163707", "268281268", "31292360");
private int currentReviewerIndex = 0;
private final PatternInfo hostPatternInfo;
private final PatternInfo reviewerPatternInfo;

public AirbnbState() {
try{
database = AirbnbSetup.getDatabase();
hostPatternInfo = new PatternInfo(List.of("131304391", "155715332", "404944621"), Scenario1Test::createAuthorizedCetAllReviewsFromHostGraphPattern);
reviewerPatternInfo = new PatternInfo(List.of("272671293", "227163707", "268281268", "31292360"), Scenario1Test::createAuthorizedGetAllReviewsFromReviewerGraphPattern);
}catch(IOException | IncorrectFormat | InterruptedException | URISyntaxException e){
throw new RuntimeException("cannot initialize benchmark state", e);
}
}

public GraphPattern nextHostPattern() {
return Scenario1Test.createAuthorizedCetAllReviewsFromHostGraphPattern(nextHostId());
public PatternInfo getHostPatternInfo() {
return hostPatternInfo;
}

public String nextHostId() {
int index = currentHostIndex;
currentHostIndex = (currentHostIndex + 1) % hostIds.size();
return hostIds.get(index);
public PatternInfo getReviewerPatternInfo() {
return reviewerPatternInfo;
}

public GraphPattern nextReviewerPattern() {
return Scenario1Test.createAuthorizedGetAllReviewsFromReviewerGraphPattern(nextReviewerId());
}

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

public PatternInfo(List<String> ids, Function<String, GraphPattern> patternGenerator) {
this.ids = ids;
this.patternGenerator = patternGenerator;
List<GraphPattern> patterns = new ArrayList<>();
for(String id : ids){
patterns.add(patternGenerator.apply(id));
}
this.patterns = List.copyOf(patterns);
}

public String nextReviewerId() {
int index = currentReviewerIndex;
currentReviewerIndex = (currentReviewerIndex + 1) % reviewerIds.size();
return reviewerIds.get(index);
public GraphPattern nextLoadedPattern() {
return patterns.get(nextIndex());
}

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

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

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

0 comments on commit ba5be1f

Please sign in to comment.