Mimic Gremlin Server with TinkerGraph?

417 views
Skip to first unread message

Vladyslav Kosulin

unread,
Dec 16, 2016, 12:53:20 PM12/16/16
to Gremlin-users
Hi all,
The code I am working on uses both TinkerGraph (as 'embedded' in memory database) and (local or remote) persistent storage with a lot of business logic implemented in shared API used with all databases.

My issue is, I can not implement parameterized traversal scripts with TinkerGraph, because there is no Client API for it, and as a result, I have to use TraversalSource.withRemote().getGraph() instead of Cluster.connect() for remote db, which is considered both memory and performance hit. I'd hate to duplicate the code with single reasoning of being able add script parameterization for remote storage.

So, is there way to connect to TinkerGraph using Gremlin Server client API, or, may be, Graph API has similar parameterization functionality I am missing?

HadoopMarc

unread,
Dec 17, 2016, 5:55:19 AM12/17/16
to Gremlin-users
Hi Vladyslav,

Not a real answer, but I notice that the gremlin-console supports non-remote, parameterized queries:

gremlin> g=TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin
> a='marko'
==>marko
gremlin
> g.V().has('name', a)
==>v[1]


When browsing through the javadoc, you see that gremlin-console uses https://docs.oracle.com/javase/8/docs/api/javax/script/ScriptEngine.html
which supports the concepts of Bindings.

This API is made available by https://github.com/apache/tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java

I would give tha latter API a try, unless better ideas pop up.

Cheers,    Marc

Op vrijdag 16 december 2016 18:53:20 UTC+1 schreef Vladyslav Kosulin:

Zurex

unread,
Apr 25, 2017, 7:37:08 AM4/25/17
to Gremlin-users
I have same problem with you, do you figure it out now?

在 2016年12月17日星期六 UTC+8上午1:53:20,Vladyslav Kosulin写道:

Stephen Mallette

unread,
Apr 25, 2017, 8:11:54 AM4/25/17
to Gremlin-users
I'm not really clear on what the original question is here. If someone can clarify I could try to help.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/66ecccfd-4372-4fff-a73b-ae0a7c7e32e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Dale

unread,
Apr 25, 2017, 9:45:35 AM4/25/17
to Gremlin-users


I think they desire to use the same 'code' for both local and remote graphs.  Secondarily, I think there's a concern that cached, parameterized scripts are more performant than bytecode (parameterized or not).

First, both scripts and traversals can actually be used locally and remotely.

For scripts, TinkerPop 3.2.4 pulls ScriptEngine support into gremlin-core.  This allows scripts to be easily executed locally.  

You can put this into gremlin console to try.

import org.apache.tinkerpop.gremlin.jsr223.CachedGremlinScriptEngineManager
manager
= new CachedGremlinScriptEngineManager();
engine
= manager.getEngineByName("gremlin-groovy");
bindings
= engine.createBindings();
bindings
.put("g", g);
bindings
.put("s", "marko");
engine
.eval("g.V().has('name',s)", bindings).next()

==>v[1]

Obviously, you can execute the same script remotely via gremlin-server using the client api to submit it.

Alternatively, native traversals can be used with or without bindings, locally and remote.

// local bindings
graph
= TinkerFactory.createModern()
g
= graph.traversal()
b
= Bindings.instance()
g
.V().has('name',b.of('x','marko'))

==>v[1]


// remote bindings
graph
= EmptyGraph.instance()
g
= graph.traversal().withRemote('conf/remote-graph.properties')
b
= Bindings.instance()
g
.V().has('name',b.of('x','marko'))

==>v[1]


Bytecode with bindings can't be cached and I'm not sure what value they provide.  However, bytecode without bindings is the fastest option there is.    See this thread

I probably wouldn't go to scripts unless there is work other than traversals that must be executed remotely. Of course, you'll have to benchmark your use cases.



On Tuesday, April 25, 2017 at 8:11:54 AM UTC-4, Stephen Mallette wrote:
I'm not really clear on what the original question is here. If someone can clarify I could try to help.
On Tue, Apr 25, 2017 at 7:34 AM, Zurex <lifer...@gmail.com> wrote:
I have same problem with you, do you figure it out now?

在 2016年12月17日星期六 UTC+8上午1:53:20,Vladyslav Kosulin写道:
Hi all,
The code I am working on uses both TinkerGraph (as 'embedded' in memory database) and (local or remote) persistent storage with a lot of business logic implemented in shared API used with all databases.

My issue is, I can not implement parameterized traversal scripts with TinkerGraph, because there is no Client API for it, and as a result, I have to use TraversalSource.withRemote().getGraph() instead of Cluster.connect() for remote db, which is considered both memory and performance hit. I'd hate to duplicate the code with single reasoning of being able add script parameterization for remote storage.

So, is there way to connect to TinkerGraph using Gremlin Server client API, or, may be, Graph API has similar parameterization functionality I am missing?

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Vladyslav Kosulin

unread,
Apr 27, 2017, 3:50:03 PM4/27/17
to Gremlin-users
Robert's interpretation of my question is 100% correct, and he pretty much answered it.
For now, we stick to direct use of Java traversal API, and connect to remote server using withRemote() without bindings, it makes debugging much easier, and we will re-evaluate switching to scripting engine later.
Reply all
Reply to author
Forward
0 new messages