Skip to content

Commit

Permalink
add new benchmark, reuse Neo4JDB objects
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Nov 24, 2024
1 parent c60b047 commit eebe9b1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ public class AirbnbBenchmark {

@Benchmark
public void scenario1GetReviewsFromHostGPEvalWithWeaving(AirbnbState state, Blackhole bh) {
Neo4jDB db = new Neo4jDB(state.transaction);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.hostPatternInfo.computeNextPattern());
Set<List<Neo4jNode>> result = GPEval.evaluate(state.neo4jDB, state.hostPatternInfo.computeNextPattern());
result.forEach(bh::consume);
}

@Benchmark
public void scenario1GetReviewsFromHostGPEvalWithoutWeaving(AirbnbState state, Blackhole bh) {
Neo4jDB db = new Neo4jDB(state.transaction);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.hostPatternInfo.nextLoadedPattern());
result.forEach(bh::consume);
Set<List<Neo4jNode>> result = GPEval.evaluate(state.neo4jDB, state.hostPatternInfo.nextLoadedPattern());
result.forEach(bh::consume);
}

@Benchmark
Expand All @@ -55,15 +53,13 @@ public void scenario1GetReviewsFromHostNeo4J(AirbnbState state, Blackhole bh) {

@Benchmark
public void scenario1GetReviewsFromReviewerGPEvalWithWeaving(AirbnbState state, Blackhole bh) {
Neo4jDB db = new Neo4jDB(state.transaction);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.reviewerPatternInfo.computeNextPattern());
Set<List<Neo4jNode>> result = GPEval.evaluate(state.neo4jDB, state.reviewerPatternInfo.computeNextPattern());
result.forEach(bh::consume);
}

@Benchmark
public void scenario1GetReviewsFromReviewerGPEvalWithoutWeaving(AirbnbState state, Blackhole bh) {
Neo4jDB db = new Neo4jDB(state.transaction);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.reviewerPatternInfo.nextLoadedPattern());
Set<List<Neo4jNode>> result = GPEval.evaluate(state.neo4jDB, state.reviewerPatternInfo.nextLoadedPattern());
result.forEach(bh::consume);
}

Expand All @@ -80,15 +76,13 @@ public void scenario1GetReviewsFromReviewerNeo4J(AirbnbState state, Blackhole bh

@Benchmark
public void scenario2GPEvalWithWeaving(AirbnbState state, Blackhole bh) {
Neo4jDB db = new Neo4jDB(state.transaction);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.scenario2PatternInfo.computeNextPattern());
Set<List<Neo4jNode>> result = GPEval.evaluate(state.neo4jDB, state.scenario2PatternInfo.computeNextPattern());
result.forEach(bh::consume);
}

@Benchmark
public void scenario2GPEvalWithoutWeaving(AirbnbState state, Blackhole bh) {
Neo4jDB db = new Neo4jDB(state.transaction);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, state.scenario2PatternInfo.nextLoadedPattern());
Set<List<Neo4jNode>> result = GPEval.evaluate(state.neo4jDB, state.scenario2PatternInfo.nextLoadedPattern());
result.forEach(bh::consume);
}

Expand All @@ -111,11 +105,13 @@ public static class AirbnbState {
private final PatternInfo<String> reviewerPatternInfo;
private final PatternInfo<Scenario2Id> scenario2PatternInfo;
private Transaction transaction;
private final Neo4jDB neo4jDB;

public AirbnbState() {
try{
database = AirbnbSetup.getDatabase();
transaction = database.beginTx();
neo4jDB = new Neo4jDB(transaction);
hostPatternInfo = new PatternInfo<>(List.of("131304391", "155715332", "404944621"), Scenario1Test::createAuthorizedCetAllReviewsFromHostGraphPattern);
reviewerPatternInfo = new PatternInfo<>(List.of("272671293", "227163707", "268281268", "31292360"), Scenario1Test::createAuthorizedGetAllReviewsFromReviewerGraphPattern);
scenario2PatternInfo = new PatternInfo<>(List.of(new Scenario2Id("278934759", "1310402"), new Scenario2Id("363134483", "1310402")), id -> Scenario2Test.editListingInNeighborhoodPattern(id.subjectId(), id.neighborhoodId()));
Expand All @@ -131,7 +127,7 @@ public PatternInfo<String> getHostPatternInfo() {
public PatternInfo<String> getReviewerPatternInfo() {
return reviewerPatternInfo;
}

@TearDown
public void closeTransaction() {
transaction.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package io.github.danthe1st.arebac.neo4j.tests.stackoverflow;

import static io.github.danthe1st.arebac.data.commongraph.attributed.AttributeValue.attribute;
import static io.github.danthe1st.arebac.data.graph_pattern.constraints.AttributeRequirementOperator.EQUAL;

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

import io.github.danthe1st.arebac.data.graph_pattern.GPEdge;
import io.github.danthe1st.arebac.data.graph_pattern.GPGraph;
import io.github.danthe1st.arebac.data.graph_pattern.GPNode;
import io.github.danthe1st.arebac.data.graph_pattern.GraphPattern;
import io.github.danthe1st.arebac.data.graph_pattern.constraints.AttributeRequirement;
import io.github.danthe1st.arebac.gpeval.GPEval;
import io.github.danthe1st.arebac.neo4j.graph.Neo4jDB;
import io.github.danthe1st.arebac.neo4j.graph.Neo4jNode;
Expand All @@ -30,8 +38,7 @@ public class SOBenchmark {

@Benchmark
public void usersCommentingTogetherGPEval(SOBenchmarkState state, Blackhole bh) {
Neo4jDB db = new Neo4jDB(state.transaction);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, SOTest.createCommentsToSameQuestionInTagPattern("name", state.nextTagName()));
Set<List<Neo4jNode>> result = GPEval.evaluate(state.neo4jDB, SOTest.createCommentsToSameQuestionInTagPattern("name", state.nextTagName()));
result.forEach(bh::consume);
}

Expand All @@ -54,8 +61,7 @@ public void usersCommentingTogetherNeo4j(SOBenchmarkState state, Blackhole bh) {

@Benchmark
public void selfAnswersInTagGPEval(SOBenchmarkState state, Blackhole bh) {
Neo4jDB db = new Neo4jDB(state.transaction);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, SOTest.createSelfAnswerPatternWithTagName(state.nextTagName()));
Set<List<Neo4jNode>> result = GPEval.evaluate(state.neo4jDB, SOTest.createSelfAnswerPatternWithTagName(state.nextTagName()));
result.forEach(bh::consume);
}

Expand All @@ -75,8 +81,7 @@ public void selfAnswersInTagNeo4j(SOBenchmarkState state, Blackhole bh) {

@Benchmark
public void selfAnswersByUserGPEval(SOBenchmarkUUIDState state, Blackhole bh) {
Neo4jDB db = new Neo4jDB(state.transaction);
Set<List<Neo4jNode>> result = GPEval.evaluate(db, SOTest.createSelfAnswerPatternWithUUID(state.nextUUID()));
Set<List<Neo4jNode>> result = GPEval.evaluate(state.neo4jDB, SOTest.createSelfAnswerPatternWithUUID(state.nextUUID()));
result.forEach(bh::consume);
}

Expand All @@ -94,17 +99,63 @@ public void selfAnswersByUserNeo4j(SOBenchmarkUUIDState state, Blackhole bh) {
}
}

@Benchmark
public void multipleSelfConnectionsbetweenUserAndQuestionNeo4J(SOBenchmarkUUIDState state, Blackhole bh) {
try(Result result = state.transaction.execute(
"""
MATCH (u:User)-[:ASKED]->(q:Question)
MATCH (u:User)-[:ASKED]->(q:Question)
MATCH (u:User)-[:ASKED]->(q:Question)
MATCH (u:User)-[:ASKED]->(q:Question)
MATCH (u:User)-[:ASKED]->(q:Question)
MATCH (u:User)-[:ASKED]->(q:Question)
MATCH (u:User)-[:ASKED]->(q:Question)
WHERE u.uuid=$uuid
RETURN q
""",
Map.of("uuid", state.nextUUID())
)){
result.forEachRemaining(bh::consume);
}
}

@Benchmark
public void multipleSelfConnectionsbetweenUserAndQuestionGPEval(SOBenchmarkUUIDState state, Blackhole bh) {
GPNode user = new GPNode("u", "User");
GPNode question = new GPNode("q", "Question");
GraphPattern pattern = new GraphPattern(
new GPGraph(
List.of(user, question),
List.of(
new GPEdge(user, question, null, "ASKED"),
new GPEdge(user, question, null, "ASKED"),
new GPEdge(user, question, null, "ASKED"),
new GPEdge(user, question, null, "ASKED"),
new GPEdge(user, question, null, "ASKED"),
new GPEdge(user, question, null, "ASKED"),
new GPEdge(user, question, null, "ASKED")
)
),
List.of(),
Map.of(user, List.of(new AttributeRequirement("uuid", EQUAL, attribute(state.nextUUID())))),
Map.of(), List.of(question), Map.of()
);
GPEval.evaluate(state.neo4jDB, pattern);
}

@State(Scope.Thread)
public static class SOBenchmarkState {
private final List<String> tagNames = List.of("neo4j", "cypher", "java");
private int currentTagIndex = 0;
private final GraphDatabaseService database;
private final Transaction transaction;
private final Neo4jDB neo4jDB;

public SOBenchmarkState() {
try{
database = SOSetup.getDatabase();
transaction = database.beginTx();
neo4jDB = new Neo4jDB(transaction);
}catch(IOException | IncorrectFormat | InterruptedException | URISyntaxException e){
throw new RuntimeException(e);
}
Expand All @@ -128,11 +179,13 @@ public static class SOBenchmarkUUIDState {
private int currentTagIndex = 0;
private final GraphDatabaseService database;
private final Transaction transaction;
private final Neo4jDB neo4jDB;

public SOBenchmarkUUIDState() {
try{
database = SOSetup.getDatabase();
transaction = database.beginTx();
neo4jDB = new Neo4jDB(transaction);
}catch(IOException | IncorrectFormat | InterruptedException | URISyntaxException e){
throw new RuntimeException(e);
}
Expand Down

0 comments on commit eebe9b1

Please sign in to comment.