baid_manish_187433 avatar image
baid_manish_187433 asked bettina.swynnerton commented

DSE Graph Connection Re-usable Object -- Traversal vs CQLSession

We have a web-application that connects to DSE Graph to search graph based on caller's request. Several graph queries are performed per HTTP request.

We are trying to figure out which driver/client should be used and the driver-object (equivalent to SQL's DataSource) that should be re-used to leverage driver's Connection Pool in most efficient manner.

There are 2 ways to connect to DSE Graph, say Client library:

  1. Tinkerpop Client: Cluster > Remote Connection > Graph Traversal

  2. DSE Java Driver: CQL Session > Remote Connection > Graph Traversal


  • Which of these client library is recommended?

  • When latest tinkerpop client is used, graph traversal 'g' should be re-used (by multiple-threads). Is this the case for DSE Driver as well? I see in OSS driver GraphTraversal class (com.datastax.dse.driver.internal.core.graph.DseGraphTraversal) is marked to be "@NotThreadSafe". Whereas CQLSession is threadsafe.


10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

bettina.swynnerton avatar image bettina.swynnerton ♦♦ commented ·

Hi @baid_manish_187433,

what is your DSE Graph version in this case?

0 Likes 0 ·
baid_manish_187433 avatar image baid_manish_187433 bettina.swynnerton ♦♦ commented ·

We are using 6.8.1

0 Likes 0 ·

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered bettina.swynnerton commented

Hi @baid_manish_187433,

I am a little confused by your reference to the different drivers, as there really is only one driver that is recommended for accessing DSE Graph 6.8, and that is the Datastax Java driver, version 4.5 and newer. You can see the compatibility here:

The latest version of the recommended driver is 4.8:

As per this docs page

there are three different ways to access the graph:

- Passing a Gremlin script directly in a plain Java string. We’ll refer to this as the script API

- Building a traversal with the TinkerPop fluent API, and executing it explicitly with the session

- Building a connected traversal with the fluent API, and executing it implicitly by invoking a terminal step

I believe your questions about thread safety are addressed in this documentation about the TinkerPop fluent API:

Note: contrary to driver statements, Tinkerpop’s GraphTraversal is mutable and therefore not thread-safe. This is fine if you just wrap a traversal into a statement and never modify it afterwards, but be careful not to share traversals and modify them concurrently.

I hope this answers your questions.

2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

baid_manish_187433 avatar image baid_manish_187433 commented ·

Thanks for the update.

Question related to driver is clear, still not clear on what should be "cached" for the lifetime of the application so that connection pooling / cost of "building the thing - connection/obects" is avoided on every request.

Is following the right way to do:

Cache "Session" and make it available to ALL the DAO objects that access different vertices.

Each DAO can further keep (if necessary) the statements (FluentGraphStatement) they use.

Basically - session is equivalent to JDBC's DataSource and FluentGraphStatement is equivalent to "PreparedStatement"

1 Like 1 ·
bettina.swynnerton avatar image bettina.swynnerton ♦♦ baid_manish_187433 commented ·

Yes, this looks like the right approach. I will double-check with the drivers team and get back to you if hear differently.

0 Likes 0 ·