diff --git a/arebac-neo4j/src/test/java/io/github/danthe1st/arebac/neo4j/tests/airbnb/AirbnbBenchmark.java b/arebac-neo4j/src/test/java/io/github/danthe1st/arebac/neo4j/tests/airbnb/AirbnbBenchmark.java index e2dc93d..1b884c4 100644 --- a/arebac-neo4j/src/test/java/io/github/danthe1st/arebac/neo4j/tests/airbnb/AirbnbBenchmark.java +++ b/arebac-neo4j/src/test/java/io/github/danthe1st/arebac/neo4j/tests/airbnb/AirbnbBenchmark.java @@ -30,16 +30,14 @@ public class AirbnbBenchmark { @Benchmark public void scenario1GetReviewsFromHostGPEvalWithWeaving(AirbnbState state, Blackhole bh) { - Neo4jDB db = new Neo4jDB(state.transaction); - Set> result = GPEval.evaluate(db, state.hostPatternInfo.computeNextPattern()); + Set> 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> result = GPEval.evaluate(db, state.hostPatternInfo.nextLoadedPattern()); - result.forEach(bh::consume); + Set> result = GPEval.evaluate(state.neo4jDB, state.hostPatternInfo.nextLoadedPattern()); + result.forEach(bh::consume); } @Benchmark @@ -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> result = GPEval.evaluate(db, state.reviewerPatternInfo.computeNextPattern()); + Set> 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> result = GPEval.evaluate(db, state.reviewerPatternInfo.nextLoadedPattern()); + Set> result = GPEval.evaluate(state.neo4jDB, state.reviewerPatternInfo.nextLoadedPattern()); result.forEach(bh::consume); } @@ -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> result = GPEval.evaluate(db, state.scenario2PatternInfo.computeNextPattern()); + Set> 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> result = GPEval.evaluate(db, state.scenario2PatternInfo.nextLoadedPattern()); + Set> result = GPEval.evaluate(state.neo4jDB, state.scenario2PatternInfo.nextLoadedPattern()); result.forEach(bh::consume); } @@ -111,11 +105,13 @@ public static class AirbnbState { private final PatternInfo reviewerPatternInfo; private final PatternInfo 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())); @@ -131,7 +127,7 @@ public PatternInfo getHostPatternInfo() { public PatternInfo getReviewerPatternInfo() { return reviewerPatternInfo; } - + @TearDown public void closeTransaction() { transaction.close(); diff --git a/arebac-neo4j/src/test/java/io/github/danthe1st/arebac/neo4j/tests/stackoverflow/SOBenchmark.java b/arebac-neo4j/src/test/java/io/github/danthe1st/arebac/neo4j/tests/stackoverflow/SOBenchmark.java index 509fce4..570fea8 100644 --- a/arebac-neo4j/src/test/java/io/github/danthe1st/arebac/neo4j/tests/stackoverflow/SOBenchmark.java +++ b/arebac-neo4j/src/test/java/io/github/danthe1st/arebac/neo4j/tests/stackoverflow/SOBenchmark.java @@ -1,5 +1,8 @@ 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; @@ -7,6 +10,11 @@ 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; @@ -30,8 +38,7 @@ public class SOBenchmark { @Benchmark public void usersCommentingTogetherGPEval(SOBenchmarkState state, Blackhole bh) { - Neo4jDB db = new Neo4jDB(state.transaction); - Set> result = GPEval.evaluate(db, SOTest.createCommentsToSameQuestionInTagPattern("name", state.nextTagName())); + Set> result = GPEval.evaluate(state.neo4jDB, SOTest.createCommentsToSameQuestionInTagPattern("name", state.nextTagName())); result.forEach(bh::consume); } @@ -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> result = GPEval.evaluate(db, SOTest.createSelfAnswerPatternWithTagName(state.nextTagName())); + Set> result = GPEval.evaluate(state.neo4jDB, SOTest.createSelfAnswerPatternWithTagName(state.nextTagName())); result.forEach(bh::consume); } @@ -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> result = GPEval.evaluate(db, SOTest.createSelfAnswerPatternWithUUID(state.nextUUID())); + Set> result = GPEval.evaluate(state.neo4jDB, SOTest.createSelfAnswerPatternWithUUID(state.nextUUID())); result.forEach(bh::consume); } @@ -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 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); } @@ -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); }