This is an automated email from the ASF dual-hosted git repository. jermy pushed a commit to branch perf-example6 in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
commit 2733ccb019ba5ff6dcbbcb53faa0a531ea710053 Author: Jermy Li <[email protected]> AuthorDate: Sat Aug 30 23:18:02 2025 +0800 perf(example): add PerfExample5 and PerfExample6 Change-Id: Ibe3df29c6926c5c58bab217220f3005d92476f7b --- .../org/apache/hugegraph/example/PerfExample1.java | 4 + .../org/apache/hugegraph/example/PerfExample2.java | 4 + .../org/apache/hugegraph/example/PerfExample4.java | 7 +- .../org/apache/hugegraph/example/PerfExample5.java | 101 +++++++++++++++++++++ .../org/apache/hugegraph/example/PerfExample6.java | 70 ++++++++++++++ .../apache/hugegraph/example/PerfExampleBase.java | 52 ++++++----- 6 files changed, 211 insertions(+), 27 deletions(-) diff --git a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample1.java b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample1.java index f015b5956..7cf3edd76 100644 --- a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample1.java +++ b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample1.java @@ -24,8 +24,10 @@ import java.util.Random; 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 @@ import com.datastax.driver.core.exceptions.NoHostAvailableException; */ public class PerfExample1 extends PerfExampleBase { + private static final Logger LOG = Log.logger(PerfExample1.class); + public static void main(String[] args) throws Exception { PerfExample1 tester = new PerfExample1(); tester.test(args); diff --git a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample2.java b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample2.java index 5dc50f80f..c984ad314 100644 --- a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample2.java +++ b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample2.java @@ -24,8 +24,10 @@ import java.util.Random; 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 @@ import com.datastax.driver.core.exceptions.NoHostAvailableException; */ public class PerfExample2 extends PerfExampleBase { + private static final Logger LOG = Log.logger(PerfExample2.class); + public static void main(String[] args) throws Exception { PerfExample2 tester = new PerfExample2(); tester.test(args); diff --git a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample4.java b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample4.java index c686e360d..9626093bf 100644 --- a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample4.java +++ b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample4.java @@ -29,7 +29,7 @@ import org.slf4j.Logger; */ public class PerfExample4 extends PerfExample3 { - private static final Logger LOG = Log.logger(PerfExample3.class); + private static final Logger LOG = Log.logger(PerfExample4.class); /** * Main method @@ -79,9 +79,4 @@ public class PerfExample4 extends PerfExample3 { LOG.info(">>>> query by range index, cost: {}ms", elapsed(current)); } } - - protected static long elapsed(long start) { - long current = System.currentTimeMillis(); - return current - start; - } } diff --git a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample5.java b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample5.java new file mode 100644 index 000000000..7b540c083 --- /dev/null +++ b/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); + } +} diff --git a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample6.java b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample6.java new file mode 100644 index 000000000..7ea9a4dde --- /dev/null +++ b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExample6.java @@ -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 + */ +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; + 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); + } +} diff --git a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExampleBase.java b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExampleBase.java index 684866674..278b6336b 100644 --- a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExampleBase.java +++ b/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); protected Set<Object> vertices = Collections.newSetFromMap(new ConcurrentHashMap<>()); protected boolean profile = false; @@ -66,6 +66,8 @@ public abstract class PerfExampleBase { int times = Integer.parseInt(args[1]); int multiple = Integer.parseInt(args[2]); this.profile = Boolean.parseBoolean(args[3]); + System.out.printf("Run: threads=%s times=%s multiple=%s profile=%s\n", + threadCount, times, multiple, this.profile); // NOTE: this test with HugeGraph is for local, // change it into a client if test with restful server from remote @@ -118,7 +120,7 @@ public abstract class PerfExampleBase { this.testQueryVertex(graph, threadCount, i, multiple); }, threadCount); - final long size = (long) (PERSON_NUM + SOFTWARE_NUM) * threadCount * times; + final long size = this.vertices.size(); LOG.info("Query rate with threads: {} vertices/s, " + "query total vertices {}, cost time: {}ms", size * 1000 / cost, size, cost); @@ -130,7 +132,7 @@ public abstract class PerfExampleBase { this.testQueryEdge(graph, threadCount, i, multiple); }, threadCount); - final long size = (long) (PERSON_NUM + SOFTWARE_NUM) * threadCount * times; + final long size = this.vertices.size(); LOG.info("Query rate with threads: {} vedges/s, " + "query total vedges {}, cost time: {}ms", size * 1000 / cost, size, cost); @@ -188,26 +190,29 @@ public abstract class PerfExampleBase { 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); } protected void testQueryEdge(GraphManager graph, int threads, int thread, int multiple) { @@ -235,6 +240,11 @@ public abstract class PerfExampleBase { totalV, thread, totalE); } + protected static long elapsed(long start) { + long current = System.currentTimeMillis(); + return current - start; + } + protected static class GraphManager { private final HugeGraph hugegraph;
