从遍历中获取顶点或路径时,Tinkerpop 非常慢



我的 Java 应用程序中有一个图形遍历,在遍历完成后,它需要 300 毫秒以上的时间来填充路径对象。 这很奇怪,因为它只发生在一些特定的遍历上,而其他遍历会立即填满它们的路径。 这是使用Tinkerpop 3.3.1的Java代码示例

我有一个情况,两个顶点通过一条边直接连接。 每次执行这个短遍历时,我都会得到很长的处理时间。如果我不执行 fill() 操作,遍历将立即完成。 我还有其他遍历,它们有超过 10 条边需要移动,它们在 1 毫秒<处理和填充路径。>

在下面的代码中,我试图找到从"origs"中的顶点到"dests"中的顶点的最短路径,而无需经过集合"避免"中的任何顶点。 遍历本身在 1 毫秒内完成,是 fill() 方法在咀嚼时钟。

Date startTime = new Date ();
if (! dests.isEmpty ()){
g.V (origs).where (is (P.without (avoids))).    
repeat (
out ().
simplePath ().
where (is (P.without (avoids)))
).
until (is (P.within (dests))).
limit (1).
path ().
fill (paths);  // This 'fill' is the line that can take > 300ms.
// When fill is removed from the code,
// this all executes within the same milli
}
Date endTime = new Date ();
// Now compare start time and end time
int diff = DateUtil.getMillisBetween  (startTime, endTime);

我也尝试过使用 toList() 方法,但这也使代码在 300 毫秒以上执行。

你的遍历是瞬时的,没有fill()toList(),因为没有"迭代",你不会得到一个结果,你只有一个GraphTraversal实例:

http://tinkerpop.apache.org/docs/current/tutorials/the-gremlin-console/#result-iteration

换句话说:

t = g.V()

创建GraphTraversal实例,并且不将g.V()的结果分配给t。另一方面:

t = g.V().toList()

将遍历迭代到List并将该结果分配给t。显然,前者将立即完成(即<1 毫秒),因为它只是构造一个对象,而后者需要更长的时间,因为它必须与您的底层图形存储交互。

最新更新