【问题标题】:Tinkerpop very slow when getting vertexes or paths from traversal从遍历中获取顶点或路径时,Tinkerpop 非常慢
【发布时间】:2018-03-07 17:15:50
【问题描述】:

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

我有一个例子,两个顶点通过一条边直接连接。每次我执行这个短暂的遍历,我都会得到很长的处理时间。如果我不执行 fill() 操作,遍历会立即完成。我有其他遍历需要遍历超过 10 条边,它们在

在下面的代码中,我试图找到从“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 毫秒。

【问题讨论】:

    标签: java graph-theory gremlin tinkerpop tinkerpop3


    【解决方案1】:

    没有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。显然,前者将立即完成(即

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 2020-09-09
      相关资源
      最近更新 更多