简体   繁体   中英

Tinkerpop very slow when getting vertexes or paths from traversal

I have a graph traversal in my Java application that is taking upwards of 300ms to fill the path object after the traversal is complete. Its strange because it only happens on some specific traversals, while other traversals fill their paths instantly. Here is the sample of the code in Java, using Tinkerpop 3.3.1

I have a case where the two vertices are directly connected by one edge. Everytime I execute this short traversal, I get the high processing time. If I don't perform the fill() operation, the traversal completes immediately. I have other traversals that have over 10 edges that need to be traveled, and they process and fill paths in < 1ms.

In the code below, I'm trying to find the shortest path from the vertex in 'origs' to the vertex in 'dests' without going through any of the vertices in the collection 'avoids'. The traversal itself completes in under 1ms, its the fill() method that is chewing up the clock.

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

I have also tried using the toList() method, but that also makes the code execute in over 300ms.

Your traversal is instantaneous without fill() or toList() because without "iteration" you don't get a result you just have a GraphTraversal instance:

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

In other words:

t = g.V()

create a GraphTraversal instance and does not assign the result of gV() to t . On the other hand:

t = g.V().toList()

iterates the traversal into a List and assigns that result to t . Obviously, the former, will complete instantaneously (ie < 1ms) as it just constructs an object whereas the latter will take longer as it must interact with your underlying graph store.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM