3

I am using Neptune (AWS) graph data base, and my client api is in java spring. My application read and write into my database. Actually we have 2 clusters for reading and writing as a bean. W e are generating several traversal and after submitting each we decided to close it by using try with ressource. Is it a best practice to close traversal and recreate it traversal().withRemote(..) ? In huge project with several connection in one thread what is the best practice?

1 Answers1

3

If your code is long running the typical best practice from Java (assuming you are using the Gremlin Java client) is to create a connection pool using the client and sharing that graph traversal source object (g) among your threads. The threads will share the connection pool. If your application is multi-threaded, a good number of threads to have to achieve high throughput is approximately twice as many as the number of virtual CPUs on the Neptune instance you are connecting to. There is no need to keep opening and closing the connection if your application is able to maintain state and is long running. If your application is more ephemeral (such as when starting and stopping containers regularly or using AWS Lambda functions) then creating and closing the connection on each invocation is often a best practice. If your code is longer running (such as in a server) then keeping a connection pool open and sharing the connections among threads in your application is usually the best approach. This avoids the overhead of creating a new connection pool each time you issue some queries.

If a connection is idle for a period of time Neptune may close it. If you are using Gremlin Java then the client includes a keep alive ping.

If you are using IAM authentication the connection will be closed after 10 days when the credentials expire.

There is some documentation here on Web Socket behavior with Amazon Neptune: https://docs.aws.amazon.com/neptune/latest/userguide/limits.html#limits-websockets

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

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38