-
Notifications
You must be signed in to change notification settings - Fork 590
perf(example): add PerfExample5 and PerfExample6 #2860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,8 +24,10 @@ | |
| import org.apache.hugegraph.HugeFactory; | ||
| import org.apache.hugegraph.backend.BackendException; | ||
| import org.apache.hugegraph.schema.SchemaManager; | ||
| import org.apache.hugegraph.util.Log; | ||
| import org.apache.tinkerpop.gremlin.structure.T; | ||
| import org.apache.tinkerpop.gremlin.structure.Vertex; | ||
| import org.slf4j.Logger; | ||
|
|
||
| import com.datastax.driver.core.exceptions.NoHostAvailableException; | ||
|
|
||
|
|
@@ -34,6 +36,8 @@ | |
| */ | ||
| public class PerfExample2 extends PerfExampleBase { | ||
|
|
||
| private static final Logger LOG = Log.logger(PerfExample2.class); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue as PerfExample1 - logger is declared but never used. Remove the unused import and logger declaration. |
||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| PerfExample2 tester = new PerfExample2(); | ||
| tester.test(args); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,101 @@ | ||||||||||||||||||
| /* | ||||||||||||||||||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||||||||||||||||||
| * contributor license agreements. See the NOTICE file distributed with this | ||||||||||||||||||
| * work for additional information regarding copyright ownership. The ASF | ||||||||||||||||||
| * licenses this file to You under the Apache License, Version 2.0 (the | ||||||||||||||||||
| * "License"); you may not use this file except in compliance with the License. | ||||||||||||||||||
| * You may obtain a copy of the License at | ||||||||||||||||||
| * | ||||||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||
| * | ||||||||||||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||||||||||||||||||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||||||||||||||||||
| * License for the specific language governing permissions and limitations | ||||||||||||||||||
| * under the License. | ||||||||||||||||||
| */ | ||||||||||||||||||
|
|
||||||||||||||||||
| package org.apache.hugegraph.example; | ||||||||||||||||||
|
|
||||||||||||||||||
| import java.util.Iterator; | ||||||||||||||||||
|
|
||||||||||||||||||
| import org.apache.hugegraph.HugeFactory; | ||||||||||||||||||
| import org.apache.hugegraph.type.define.Directions; | ||||||||||||||||||
| import org.apache.hugegraph.util.Log; | ||||||||||||||||||
| import org.apache.tinkerpop.gremlin.structure.Edge; | ||||||||||||||||||
| import org.slf4j.Logger; | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment says 'query vertices/adj-edges by ids' but this class only provides vertex and edge querying functionality. The comment should be more specific about what this example demonstrates compared to PerfExample3.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PerfExample3 is a test for: insert vertices with indexes in order |
||||||||||||||||||
| * Perf test for: query vertices/adj-edges by ids | ||||||||||||||||||
| */ | ||||||||||||||||||
| public class PerfExample5 extends PerfExample3 { | ||||||||||||||||||
|
|
||||||||||||||||||
| private static final Logger LOG = Log.logger(PerfExample5.class); | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Main method | ||||||||||||||||||
| * @param args 3 arguments, 1st should be 1, meaning single thread, | ||||||||||||||||||
| * product of 2nd and 3rd is total number of "person" vertices | ||||||||||||||||||
| * @throws InterruptedException | ||||||||||||||||||
| */ | ||||||||||||||||||
| public static void main(String[] args) throws Exception { | ||||||||||||||||||
| PerfExample5 tester = new PerfExample5(); | ||||||||||||||||||
| tester.test(args); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Stop daemon thread | ||||||||||||||||||
| HugeFactory.shutdown(30L); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| @Override | ||||||||||||||||||
| protected void testQueryVertex(GraphManager graph, | ||||||||||||||||||
| int threads, | ||||||||||||||||||
| int thread, | ||||||||||||||||||
| int multiple) { | ||||||||||||||||||
| int totalV = 0; | ||||||||||||||||||
| long start = System.currentTimeMillis(); | ||||||||||||||||||
| for (int i = 0; i < multiple; i++) { | ||||||||||||||||||
| int j = 0; | ||||||||||||||||||
| for (Object id : this.vertices) { | ||||||||||||||||||
| if (j++ % threads != thread) { | ||||||||||||||||||
| continue; | ||||||||||||||||||
| } | ||||||||||||||||||
| graph.queryVertex(id); | ||||||||||||||||||
| totalV++; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| long cost = elapsed(start); | ||||||||||||||||||
| LOG.info("Query {} vertices with thread({}): {} vertices/s", | ||||||||||||||||||
| totalV, thread, totalV * 1000 / cost); | ||||||||||||||||||
|
Comment on lines
+67
to
+68
|
||||||||||||||||||
| LOG.info("Query {} vertices with thread({}): {} vertices/s", | |
| totalV, thread, totalV * 1000 / cost); | |
| if (cost == 0) { | |
| LOG.info("Query {} vertices with thread({}): N/A vertices/s (cost=0)", totalV, thread); | |
| } else { | |
| LOG.info("Query {} vertices with thread({}): {} vertices/s", | |
| totalV, thread, totalV * 1000 / cost); | |
| } |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Division by zero error will occur if 'cost' is 0. Add a check to prevent division by zero before calculating vertices/s and edges/s.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with this | ||
| * work for additional information regarding copyright ownership. The ASF | ||
| * licenses this file to You under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.hugegraph.example; | ||
|
|
||
| import org.apache.hugegraph.HugeFactory; | ||
| import org.apache.hugegraph.util.Log; | ||
| import org.apache.tinkerpop.gremlin.structure.T; | ||
| import org.apache.tinkerpop.gremlin.structure.Vertex; | ||
| import org.slf4j.Logger; | ||
|
|
||
| /** | ||
| * Perf test for: query vertices/adj-edges by ids with edges insert | ||
| */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment is identical to PerfExample5 but this class has different functionality (batch insertion with edges). Update the comment to accurately describe what PerfExample6 demonstrates.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this PerfExample6 test, we insert some edges (one edge per vertex) for adj-edges test. |
||
| public class PerfExample6 extends PerfExample5 { | ||
|
|
||
| private static final Logger LOG = Log.logger(PerfExample6.class); | ||
|
|
||
| /** | ||
| * Main method | ||
| * @param args 3 arguments, 1st should be 1, meaning single thread, | ||
| * product of 2nd and 3rd is total number of "person" vertices | ||
| * @throws InterruptedException | ||
| */ | ||
| public static void main(String[] args) throws Exception { | ||
| PerfExample6 tester = new PerfExample6(); | ||
| tester.test(args); | ||
|
|
||
| // Stop daemon thread | ||
| HugeFactory.shutdown(30L); | ||
| } | ||
|
|
||
| @Override | ||
| protected void testInsert(GraphManager graph, int times, int multiple) { | ||
| final int TIMES = times * multiple; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider extracting the BATCH constant to a class-level constant or making it configurable, as hardcoded values like 100 reduce flexibility for performance testing.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only the insertion test involves batch, and batch is not a dimension we test, so keep it for now. |
||
| final int BATCH = 100; | ||
| long total = 0; | ||
| Vertex lastV = null; | ||
| // Insert in order | ||
| for (int i = 0; i < TIMES; i++) { | ||
| for (int j = 0; j < BATCH; j++) { | ||
| String name = String.format("p-%08d", total++); | ||
| Vertex v = graph.addVertex(T.label, "person", "name", name, | ||
| "city", "Hongkong", "age", 3); | ||
| this.vertices.add(v.id()); | ||
|
|
||
| if (lastV != null) { | ||
| v.addEdge("knows", lastV); | ||
| } | ||
| lastV = v; | ||
| } | ||
| graph.tx().commit(); | ||
| } | ||
| LOG.info("Insert {} vertices and {} edges", total, total - 1L); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -51,7 +51,7 @@ public abstract class PerfExampleBase { | |||||||||||||||||
| public static final int SOFTWARE_NUM = 30; | ||||||||||||||||||
| public static final int EDGE_NUM = 100; | ||||||||||||||||||
|
|
||||||||||||||||||
| protected static final Logger LOG = Log.logger(PerfExampleBase.class); | ||||||||||||||||||
| private static final Logger LOG = Log.logger(PerfExampleBase.class); | ||||||||||||||||||
|
||||||||||||||||||
| private static final Logger LOG = Log.logger(PerfExampleBase.class); | |
| protected static final Logger LOG = Log.logger(PerfExampleBase.class); |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Division by zero error will occur if 'cost' is 0. Add a check to prevent division by zero before calculating vertices/s.
| LOG.info("Query {} vertices with thread({}): {} vertices/s", | |
| totalV, thread, totalV * 1000 / cost); | |
| if (cost == 0) { | |
| LOG.info("Query {} vertices with thread({}): N/A vertices/s (cost=0ms)", totalV, thread); | |
| } else { | |
| LOG.info("Query {} vertices with thread({}): {} vertices/s", | |
| totalV, thread, totalV * 1000 / cost); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good refactoring to move the elapsed() method to the base class where it can be reused by all performance examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logger declaration in PerfExample1 and PerfExample2 is added but never used. Consider removing these unused imports and logger declarations to avoid dead code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this time we marked the PerfExampleBase.LOG as private.