I have 500 vertices and 400 edges in remote graph created with janusgraph and I use tinkerpop.gremlin to search. But opening a GraphTraversalSource and closing it tends to be time consuming.For example, if a neo4j's query takes 200ms, the corresponding operation in janusgraph takes about 4 minutes.
I've searched Google and official documentations but did not find anything that could solve the issue I face.
Here is a sample code:
public class ALittleTest {
public static void main(String[] args) throws Exception{
double startTime = System.currentTimeMillis();
String objectID = "xxxxxxxxxxxxxxx";
// open graph
Graph graph = EmptyGraph.instance();
GraphTraversalSource g = graph.traversal().withRemote("remote-graph.properties");
double makeGraphTime = System.currentTimeMillis();
// query
Vertex rootVertex = g.V().has("ID", objectID).next();
double queryGraphTime = System.currentTimeMillis();
// close graph
g.close();
double endTime = System.currentTimeMillis();
double queryTime = (queryGraphTime - makeGraphTime)/1000.00;
double usedTime = (endTime - startTime)/1000.00;
System.out.println(queryTime);
System.out.println(usedTime);
}
}
the result of code above is:
"queryTime":0.538,"usedTime":4.307.
It seems that open the connection with gremlin-server and close it takes a lot of time. How can we improve the performance?
Creation and destruction of the connection to the server is expensive. I don't think there is anything you can do to specifically speed up either of those processes. Of course, you really shouldn't be creating and destroying connections with any regularity. You should create and re-use the connection you make to the server for the life of your application. That said, four minutes even with opening and closing the connection seems outside of what I would normally expect for execution time, so there may be other issues at play.