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 629c2ed568..b5ec0506f4 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 @@ -53,8 +53,7 @@ public abstract class PerfExampleBase { protected static final Logger LOG = Log.logger(PerfExampleBase.class); - protected Set vertices = Collections.newSetFromMap( - new ConcurrentHashMap<>()); + protected Set vertices = Collections.newSetFromMap(new ConcurrentHashMap<>()); protected boolean profile = false; public int test(String[] args) throws Exception { @@ -68,8 +67,8 @@ public int test(String[] args) throws Exception { int multiple = Integer.parseInt(args[2]); this.profile = Boolean.parseBoolean(args[3]); - // NOTE: this test with HugeGraph is for local, change it into - // client if test with restful server from remote + // NOTE: this test with HugeGraph is for local, + // change it into a client if test with restful server from remote HugeGraph hugegraph = ExampleUtil.loadGraph(true, this.profile); GraphManager graph = new GraphManager(hugegraph); @@ -87,24 +86,19 @@ public int test(String[] args) throws Exception { /** * Multi-threaded and multi-commits and batch insertion test - * @param graph graph - * @param threadCount - * The count of threads that perform the insert operation at the - * same time - * @param times - * The transaction commit times for each thread - * @param multiple - * The coefficient to multiple number of vertices(100) and edges(100) - * for each transaction commit - * @throws Exception execute may throw Exception + * + * @param graph graph + * @param threadCount The count of threads that perform the insert operation at the + * same time + * @param times The transaction commit times for each thread + * @param multiple The coefficient to multiple number of vertices(100) and edges(100) + * for each transaction commit + * @throws Exception execute may throw Exception */ - public void testInsertPerf(GraphManager graph, - int threadCount, - int times, - int multiple) - throws Exception { + public void testInsertPerf(GraphManager graph, int threadCount, int times, int multiple) + throws Exception { // Total vertices/edges - long n = threadCount * times * multiple; + long n = (long) threadCount * times * multiple; long vertices = (PERSON_NUM + SOFTWARE_NUM) * n; long edges = EDGE_NUM * n; @@ -114,37 +108,29 @@ public void testInsertPerf(GraphManager graph, LOG.info("Insert rate with threads: {} vertices/s & {} edges/s, " + "insert total {} vertices & {} edges, cost time: {}ms", - vertices * 1000 / cost, edges * 1000 / cost, - vertices, edges, cost); - + vertices * 1000 / cost, edges * 1000 / cost, vertices, edges, cost); graph.clearVertexCache(); } - public void testQueryVertexPerf(GraphManager graph, - int threadCount, - int times, - int multiple) - throws Exception { + public void testQueryVertexPerf(GraphManager graph, int threadCount, int times, int multiple) + throws Exception { long cost = this.execute(graph, i -> { this.testQueryVertex(graph, threadCount, i, multiple); }, threadCount); - final long size = (PERSON_NUM + SOFTWARE_NUM) * threadCount * times; + final long size = (long) (PERSON_NUM + SOFTWARE_NUM) * threadCount * times; LOG.info("Query rate with threads: {} vertices/s, " + "query total vertices {}, cost time: {}ms", size * 1000 / cost, size, cost); } - public void testQueryEdgePerf(GraphManager graph, - int threadCount, - int times, - int multiple) - throws Exception { + public void testQueryEdgePerf(GraphManager graph, int threadCount, int times, int multiple) + throws Exception { long cost = this.execute(graph, i -> { this.testQueryEdge(graph, threadCount, i, multiple); }, threadCount); - final long size = (PERSON_NUM + SOFTWARE_NUM) * threadCount * times; + final long size = (long) (PERSON_NUM + SOFTWARE_NUM) * threadCount * times; LOG.info("Query rate with threads: {} vedges/s, " + "query total vedges {}, cost time: {}ms", size * 1000 / cost, size, cost); @@ -152,8 +138,8 @@ public void testQueryEdgePerf(GraphManager graph, protected long execute(GraphManager graph, Consumer task, int threadCount) throws Exception { - CyclicBarrier startBarrier = new CyclicBarrier(threadCount + 1); - CyclicBarrier endBarrier = new CyclicBarrier(threadCount + 1); + CyclicBarrier startBarrier = new CyclicBarrier(threadCount + 1); + CyclicBarrier endBarrier = new CyclicBarrier(threadCount + 1); List threads = new ArrayList<>(threadCount); for (int i = 0; i < threadCount; i++) { int j = i; @@ -200,14 +186,9 @@ protected long execute(GraphManager graph, Consumer task, protected abstract void initSchema(SchemaManager schema); - protected abstract void testInsert(GraphManager graph, - int times, - int multiple); + protected abstract void testInsert(GraphManager graph, int times, int multiple); - protected void testQueryVertex(GraphManager graph, - int threads, - int thread, - int multiple) { + protected void testQueryVertex(GraphManager graph, int threads, int thread, int multiple) { int i = 0; int j = 0; int total = 0; @@ -229,10 +210,7 @@ protected void testQueryVertex(GraphManager graph, LOG.debug("Query vertices with thread({}): {}", thread, total); } - protected void testQueryEdge(GraphManager graph, - int threads, - int thread, - int multiple) { + protected void testQueryEdge(GraphManager graph, int threads, int thread, int multiple) { int i = 0; int j = 0; int totalV = 0; @@ -258,9 +236,8 @@ protected void testQueryEdge(GraphManager graph, } protected static class GraphManager { - private HugeGraph hugegraph; - private Cache cache = CacheManager.instance() - .cache("perf-test"); + private final HugeGraph hugegraph; + private final Cache cache = CacheManager.instance().cache("perf-test"); public GraphManager(HugeGraph hugegraph) { this.hugegraph = hugegraph; @@ -268,13 +245,11 @@ public GraphManager(HugeGraph hugegraph) { public void initEnv() { // Cost about 6s - Whitebox.invoke(this.hugegraph.getClass(), - "graphTransaction", this.hugegraph); + Whitebox.invoke(this.hugegraph.getClass(), "graphTransaction", this.hugegraph); } public void destroyEnv() { - Whitebox.invoke(this.hugegraph.getClass(), - "closeTx", this.hugegraph); + Whitebox.invoke(this.hugegraph.getClass(), "closeTx", this.hugegraph); } public Transaction tx() {