You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by "Marko A. Rodriguez (JIRA)" <ji...@apache.org> on 2016/09/13 18:33:20 UTC

[jira] [Commented] (TINKERPOP-1444) Benchmark bytecode->Traversal creation and implement GremlinServer cache if necessary.

    [ https://issues.apache.org/jira/browse/TINKERPOP-1444?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15488012#comment-15488012 ] 

Marko A. Rodriguez commented on TINKERPOP-1444:
-----------------------------------------------

So, having a {{Map<Bytecode,Traversal>}} is ~100x faster than generating the traversal from the bytecode via a {{Translator}}.

Here is the benchmark I created in {{TinkerPlayTest}}.

{code}
public void testPlay8() throws Exception {
        Graph graph = TinkerFactory.createModern();
        GraphTraversalSource g = graph.traversal();

        final Traversal<?, ?> traversal = g.V().repeat(out()).times(2).groupCount().by("name").select(Column.keys).order().by(Order.decr);
        final Bytecode bytecode = traversal.asAdmin().getBytecode();
        System.out.println("BYTECODE: " + bytecode + "\n");
        Map<Bytecode, Traversal.Admin<?, ?>> cache = new HashMap<>();
        cache.put(bytecode, traversal.asAdmin());
        final HashSet<?> result = new LinkedHashSet<>(Arrays.asList("ripple", "lop"));

        System.out.println("Bytecode->Traversal.clone() cache: " + TimeUtil.clock(1000, () -> {
            final Traversal.Admin<?, ?> t = cache.get(bytecode).clone();
            //assertEquals(result, t.next());
        }));

        System.out.println("Bytecode->JavaTranslator call    : " + TimeUtil.clock(1000, () -> {
            final Traversal t = JavaTranslator.of(g).translate(bytecode);
            //assertEquals(result, t.next());
        }));

        System.out.println("\n==Second test with reversed execution==\n");

        System.out.println("Bytecode->JavaTranslator call    : " + TimeUtil.clock(1000, () -> {
            final Traversal t = JavaTranslator.of(g).translate(bytecode);
            //assertEquals(result, t.next());
        }));

        System.out.println("Bytecode->Traversal.clone() cache: " + TimeUtil.clock(1000, () -> {
            final Traversal.Admin<?, ?> t = cache.get(bytecode).clone();
            //assertEquals(result, t.next());
        }));
    }
{code}

The print stream looks as follows:

{code}
BYTECODE: [[], [V(), repeat([[], [out()]]), times(2), groupCount(), by(name), select(keys), order(), by(decr)]]

Bytecode->Traversal.clone() cache: 0.025821273999999998
Bytecode->JavaTranslator call    : 0.13305238800000002

==Second test with reversed execution==

Bytecode->JavaTranslator call    : 0.098383349
Bytecode->Traversal.clone() cache: 0.008491400999999999
{code}

CONCLUSION: We should add a Bytecode->Traversal.clone() cache to GremlinServer. This will also speed up Groovy-style traversals as you don't have any string/compiled script translation to do. Über faster.

> Benchmark bytecode->Traversal creation and implement GremlinServer cache if necessary.
> --------------------------------------------------------------------------------------
>
>                 Key: TINKERPOP-1444
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1444
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: benchmark, language-variant, process, server
>    Affects Versions: 3.2.2
>            Reporter: Marko A. Rodriguez
>
> Right now, when you send {{Bytecode}} to GremlinServer, it will convert the bytecode to a traversal either via Java reflection (Gremlin-Java) or script engine evaluation (e.g. Gremlin-Groovy, Gremlin-Python).
> We should see how fast the process is to go from Bytecode to Traversal and if its "slow" we should create a {{Map<Bytecode,Traversal>}}-cache in GremlinServer.
> The reasons it may be "slow" are:
> 1. {{JavaTranslator}} uses Java reflection to translate bytecode to traversal and that code is a little "thick" and either should be optimized (if possible) or, instead, bytecode/traversal translations should be cached.
> 2. {{Groovy/PythonTranslator}} uses string construction to generate a script from the bytecode. While that script may be cached, it would be good if we have a cache prior to that which simply just grabs the traversal from a bytecode cache.
> I think that we will definitely want a cache as it should make things fast, but it will be good to know how much faster prior to diving into such work.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)