Java – What are the best practices for gremlin client clustering in Java spring projects

What are the best practices for gremlin client clustering in Java spring projects… here is a solution to the problem.

What are the best practices for gremlin client clustering in Java spring projects

I’m using Neptune (AWS) graph database and my client APIs are in Java spring. My application reads and writes to my database. In fact, we have 2 clusters reading and writing as one bean. We are generating multiple traversals, and after committing each one, we decide to use try with ressource closes it. .
Is it best practice to turn off traversal().withRemote(..) by turning off traversal().withRemote(..) ?
What are the best practices for large projects with multiple connections in one thread?

Solution

If your code is long-running, a typical best practice for Java (assuming you are using the Gremlin Java client) is to use the client to create a pool of connections and share the graph between your threads traversing the source object (g). Threads share the connection pool. If your application is multithreaded, the large number of threads required to achieve high throughput is approximately twice the number of virtual CPUs on the Neptune instance that you are connected to. If your application remains in state and runs for a long time, you do not need to continue to open and close connections. If your application is more ephemeral, such as periodically starting and stopping containers or using AWS Lambda functions, it’s often a best practice to create and close connections on each invocation. If your code runs longer, such as in a server, it is often best to keep the connection pool open and share connections between your application’s threads. This avoids the overhead of creating a new connection pool each time some queries are issued.

If the connection is idle for a while, Neptune might shut it down. If you are using Gremlin Java, the client includes a ping that persists the activity state.

If you use IAM authentication, the connection is closed 10 days after the credentials expire.

Here is some documentation about Amazon Neptune’s Web Socket behavior: https://docs.aws.amazon.com/neptune/latest/userguide/limits.html#limits-websockets

There is some additional information related to Java clients here: https://docs.aws.amazon.com/neptune/latest/userguide/best-practices-gremlin-java-client.html

Related Problems and Solutions