DataStax Academy FAQ

DataStax Academy migrated to a new learning management system (LMS) in July 2020. We are also moving to a new Cassandra Certification process so there are changes to exam bookings, voucher system and issuing of certificates.

Check out the Academy FAQ pages for answers to your questions:


question

baid_manish_187433 avatar image
baid_manish_187433 asked ·

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

Questions:

  • 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.

Thanks

graph
2 comments
10 |1000 characters needed characters left characters exceeded

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

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 ♦♦ ·

We are using 6.8.1

0 Likes 0 · ·

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered ·

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:

https://docs.datastax.com/en/driver-matrix/doc/driver_matrix/javaDrivers.html

The latest version of the recommended driver is 4.8:

https://docs.datastax.com/en/developer/java-driver/4.8/

As per this docs page

https://docs.datastax.com/en/developer/java-driver/4.8/manual/core/dse/graph/

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:

https://docs.datastax.com/en/developer/java-driver/4.8/manual/core/dse/graph/fluent/explicit/#creating-fluent-statements

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 characters needed characters left characters exceeded

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

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"

0 Likes 0 · ·

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 · ·