gpt4 book ai didi

java - 如何解决gremlin用Java查询janusgraph花费太多时间的问题?

转载 作者:行者123 更新时间:2023-12-02 01:01:12 24 4
gpt4 key购买 nike

我在使用 janusgraph 创建的远程图中有 500 个顶点和 400 个边,我使用tinkerpop.gremlin 进行搜索。但是打开一个GraphTraversalSource并关闭它往往会很耗时。例如,如果neo4j的查询需要200ms,那么janusgraph中的相应操作大约需要4分钟。

我搜索了 Google 和官方文档,但没有找到任何可以解决我面临的问题的内容。

这里是一个示例代码:

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);
}
}

上面代码的结果是:

"queryTime":0.538,"usedTime":4.307. 

似乎打开与 gremlin-server 的连接并关闭需要花费很多时间。我们如何提高性能?

最佳答案

创建和销毁与服务器的连接的成本很高。我认为您无法采取任何措施来专门加速这两个过程。当然,您确实不应该有规律地创建和破坏连接。您应该在应用程序的生命周期内创建并重复使用与服务器建立的连接。也就是说,即使打开和关闭连接,四分钟似乎超出了我通常预期的执行时间,因此可能还有其他问题。

关于java - 如何解决gremlin用Java查询janusgraph花费太多时间的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57767623/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com