Skip to content

Commit

Permalink
Update PerfExampleBase.java
Browse files Browse the repository at this point in the history
  • Loading branch information
imbajin committed Nov 13, 2023
1 parent 0886bc3 commit 626103f
Showing 1 changed file with 30 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public abstract class PerfExampleBase {

protected static final Logger LOG = Log.logger(PerfExampleBase.class);

protected Set<Object> vertices = Collections.newSetFromMap(
new ConcurrentHashMap<>());
protected Set<Object> vertices = Collections.newSetFromMap(new ConcurrentHashMap<>());
protected boolean profile = false;

public int test(String[] args) throws Exception {
Expand All @@ -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);

Expand All @@ -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;

Expand All @@ -114,46 +108,38 @@ 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);
}

protected long execute(GraphManager graph, Consumer<Integer> 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<Thread> threads = new ArrayList<>(threadCount);
for (int i = 0; i < threadCount; i++) {
int j = i;
Expand Down Expand Up @@ -200,14 +186,9 @@ protected long execute(GraphManager graph, Consumer<Integer> 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;
Expand All @@ -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;
Expand All @@ -258,23 +236,20 @@ protected void testQueryEdge(GraphManager graph,
}

protected static class GraphManager {
private HugeGraph hugegraph;
private Cache<Id, Object> cache = CacheManager.instance()
.cache("perf-test");
private final HugeGraph hugegraph;
private final Cache<Id, Object> cache = CacheManager.instance().cache("perf-test");

public GraphManager(HugeGraph hugegraph) {
this.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() {
Expand Down

0 comments on commit 626103f

Please sign in to comment.