Gremlin 小精灵和simplePath需要很长时间

Gremlin 小精灵和simplePath需要很长时间,gremlin,tinkerpop,gremlinpython,Gremlin,Tinkerpop,Gremlinpython,我使用docker的gremlin服务器 图片:tinkerpop/gremlin服务器:3.4.2 gremlinpython=“==3.4.2” 我想得到从V(1)到V(3)的路径,但出了点问题 g.V(1).repeat(__.outE().inV()).until(__.hasId("3")).path() > raised gremlin_python.driver.protocol.GremlinServerError g.V(1).repeat(__.o

我使用docker的gremlin服务器
图片:tinkerpop/gremlin服务器:3.4.2
gremlinpython=“==3.4.2”

我想得到从V(1)到V(3)的路径,但出了点问题

g.V(1).repeat(__.outE().inV()).until(__.hasId("3")).path()
> raised gremlin_python.driver.protocol.GremlinServerError

g.V(1).repeat(__.outE().inV()).until(__.hasId(3)).path().limit(1)
[path[v[1], e[e1][1-route->2], v[2], e[e2][2-route->3], v[3]]]

g.V(1).repeat(__.outE().inV().simplePath()).until(__.hasId(3)).path().limit(1)
> raised gremlin_python.driver.protocol.GremlinServerError

限制使变快,但为什么simplePath()使变慢

g.V(1).repeat(__.outE().inV().simplePath()).times(2).path().limit(1)
[path[v[1], e[e1][1-route->2], v[2], e[e2][2-route->3], v[3]]]

g.V(1).repeat(__.outE().inV().simplePath()).until(__.hasId(3)).path().limit(1)
> raised gremlin_python.driver.protocol.GremlinServerError

为什么蒂尔走得这么慢?

从你的问题中我可以看出,这个基本遍历:

g.V(1).repeat(__.outE().inV().simplePath()).times(2).path().limit(1)
[path[v[1], e[e1][1-route->2], v[2], e[e2][2-route->3], v[3]]]

g.V(1).repeat(__.outE().inV().simplePath()).until(__.hasId(3)).path().limit(1)
> raised gremlin_python.driver.protocol.GremlinServerError
g.V(1).repeat(__.outE().inV()).until(__.hasId("3")).path()
是相当昂贵的,事实上,如果图中存在介于“1”和“3”之间的循环,则可能永远不会终止。结果,它超时了。通过使用
simplePath()
(以消除循环)和
limit(1)
过滤这些路径,您可以采取正确的方法来解决此问题,以获得它找到的第一个匹配,然后终止。您在该遍历中的组合似乎应该是编写此查询的适当方式:

g.V(1).repeat(__.outE().inV().simplePath()).until(__.hasId(3)).path().limit(1)
但是,当这个遍历似乎能给你一个答案时,它就会超时:

g.V(1).repeat(__.outE().inV().simplePath()).times(2).path().limit(1)
请注意,
times(2)
的使用确实改变了遍历的执行模型(对于大多数图),其中
repeat()
展开并开始(您可以通过
profile()
步骤看到不同的执行模型)。我认为这就是为什么这个遍历实际上完成了,并且没有超时


最后,我认为这里的问题是,正在处理的路径太多,使用
simplePath()
进行路径检查的额外成本可能会将基本遍历推到超时时间的边缘。很难说清楚。我将尝试
profile()
使用您的数据进行各种遍历(增加服务器上的超时),并查看它们正在处理多少个遍历器。这应该能更好地提示正在发生的事情。

从您的问题中我可以看出,这个基本遍历:

g.V(1).repeat(__.outE().inV()).until(__.hasId("3")).path()
是相当昂贵的,事实上,如果图中存在介于“1”和“3”之间的循环,则可能永远不会终止。结果,它超时了。通过使用
simplePath()
(以消除循环)和
limit(1)
过滤这些路径,您可以采取正确的方法来解决此问题,以获得它找到的第一个匹配,然后终止。您在该遍历中的组合似乎应该是编写此查询的适当方式:

g.V(1).repeat(__.outE().inV().simplePath()).until(__.hasId(3)).path().limit(1)
但是,当这个遍历似乎能给你一个答案时,它就会超时:

g.V(1).repeat(__.outE().inV().simplePath()).times(2).path().limit(1)
请注意,
times(2)
的使用确实改变了遍历的执行模型(对于大多数图),其中
repeat()
展开并开始(您可以通过
profile()
步骤看到不同的执行模型)。我认为这就是为什么这个遍历实际上完成了,并且没有超时


最后,我认为这里的问题是,正在处理的路径太多,使用
simplePath()
进行路径检查的额外成本可能会将基本遍历推到超时时间的边缘。很难说清楚。我将尝试
profile()
使用您的数据进行各种遍历(增加服务器上的超时),并查看它们正在处理多少个遍历器。这应该可以更好地提示正在发生的情况。

请您将实际发生的错误包括在内,好吗
GremlinServerError
可能意味着很多事情。如果客户端错误没有提供其他信息,您可能需要查看docker中的控制台输出,以了解服务器端错误。考虑到您使用的TinkerPop版本有多旧,这也很有可能——那里的错误消息可能不像今天这样强大。对不起,谢谢。错误如下
gremlin_python.driver.protocol.GremlinServerError:598:{“requestId”:“xxxxx”,“code”:“TimeLimitExceedexceception”,“detailedMessage”:“脚本内发生超时,或者在计算[RequestMessage{,requestId=xxxxx,op='bytecode',processor='traversal',args={gremlin=[],[V(1)时直接取消了超时。”,重复([[]、[outE()、inV()、simplePath()]),直到([[]、[hasId(3)])、path()、limit(1)]、别名={g=g}}}}]“}
您能不能包括您得到的实际错误
GremlinServerError
可能意味着很多事情。如果客户端错误没有提供其他信息,您可能需要查看docker中的控制台输出,以了解服务器端错误。考虑到您使用的TinkerPop版本有多旧,这也很有可能——那里的错误消息可能不像今天这样强大。对不起,谢谢。错误如下
gremlin_python.driver.protocol.GremlinServerError:598:{“requestId”:“xxxxx”,“code”:“TimeLimitExceedexceception”,“detailedMessage”:“脚本内发生超时,或者在计算[RequestMessage{,requestId=xxxxx,op='bytecode',processor='traversal',args={gremlin=[],[V(1)时直接取消了超时。”,重复([[]、[outE()、inV()、simplePath()]),直到([[]、[hasId(3)])、path()、limit(1)]、别名={g=g}}}}]“}