Copilot commented on code in PR #2860: URL: https://github.com/apache/incubator-hugegraph/pull/2860#discussion_r2313262098
########## hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExampleBase.java: ########## @@ -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); Review Comment: Changing the Logger from 'protected' to 'private' breaks inheritance for subclasses that may need to access the logger. Consider keeping it protected or having subclasses define their own loggers. ```suggestion protected static final Logger LOG = Log.logger(PerfExampleBase.class); ``` ########## hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExampleBase.java: ########## @@ -188,26 +190,29 @@ protected long execute(GraphManager graph, Consumer<Integer> task, protected abstract void testInsert(GraphManager graph, int times, int multiple); - protected void testQueryVertex(GraphManager graph, int threads, int thread, int multiple) { - int i = 0; - int j = 0; - int total = 0; - for (Object id : this.vertices) { - if (i++ % multiple != 0) { - continue; - } - if (j++ % threads != thread) { - continue; - } - - LOG.debug("Query vertex {}: {}", i, id); - Vertex vertex = graph.queryVertex(id); - if (!vertex.id().equals(id)) { - LOG.warn("Query vertex by id {} returned {}", id, vertex); + 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; + } + LOG.debug("Query vertex {}: {}", i, id); + Vertex vertex = graph.queryVertex(id); + if (!vertex.id().equals(id)) { + LOG.warn("Query vertex by id {} returned {}", id, vertex); + } + totalV++; } - total++; } - LOG.debug("Query vertices with thread({}): {}", thread, total); + long cost = elapsed(start); + LOG.info("Query {} vertices with thread({}): {} vertices/s", + totalV, thread, totalV * 1000 / cost); Review Comment: Division by zero error will occur if 'cost' is 0. Add a check to prevent division by zero before calculating vertices/s. ```suggestion 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); } ``` ########## hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample5.java: ########## @@ -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; + +/** + * 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); + } + + @Override + protected void testQueryEdge(GraphManager graph, + int threads, + int thread, + int multiple) { + int totalV = 0; + int totalE = 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; + } + + Iterator<Edge> edges = graph.queryVertexEdge(id, Directions.OUT); + while (edges.hasNext()) { + edges.next(); + totalE++; + } + totalV++; + } + } + long cost = elapsed(start); + LOG.info("Query {} edges of vertices({}) with thread({}): " + + "{} vertices/s, {} edges/s", + totalE, totalV, thread, + totalV * 1000 / cost, totalE * 1000 / cost); Review Comment: 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. ########## hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample5.java: ########## @@ -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; + +/** + * 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); Review Comment: Division by zero error will occur if 'cost' is 0. Add a check to prevent division by zero before calculating vertices/s. ```suggestion 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); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org For additional commands, e-mail: issues-h...@hugegraph.apache.org