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

Mat*_*own 1 java graph-theory gremlin tinkerpop tinkerpop3

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

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

在下面的代码中,我试图找到从“origs”中的顶点到“dests”中的顶点的最短路径,而不经过集合“avoids”中的任何顶点。遍历本身在 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);
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用 toList() 方法,但这也使得代码执行时间超过 300 毫秒。

ste*_*tte 5

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

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

换句话说:

t = g.V()
Run Code Online (Sandbox Code Playgroud)

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

t = g.V().toList()
Run Code Online (Sandbox Code Playgroud)

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