1

Currently I am using Aerospike in my application. I faced lots of timeout issues as shown below when I was creating new java client for each transaction and I was not closing it so number of connection ramp up dramatically.

Aerospike Error: (9) Client timeout: timeout=1000 iterations=1 failedNodes=0 failedConns=0

so to resolve this timeout issue,I didn't made any changes to client, read and write policy, I just created only one client, stored it's instance in some variable and used this same client for all transaction (get or put requests). now I want to understand how moving from multiple client to one client resolved my timeout issue. how these connection were not closing automatically.

2 Answers 2

3

The AerospikeClient constructor requests peers, partition maps and racks for all nodes in the cluster and initializes connection pools and async eventloops. This is an expensive process that is only meant to be performed once per cluster at application startup. AerospikeClient is thread-safe, so instances can be shared between threads.

If AerospikeClient close() is not called, connections residing in the pools (at least one connection pool per node) will not be closed. There are no finalize() methods in AerospikeClient.

The first transaction(s) usually need to create new connections. This adds to the latency and can cause timeouts.

Sign up to request clarification or add additional context in comments.

Comments

2

The client does more than just the application's transactions. It also monitors the cluster for changes so that it can maintain one hop per transaction. Also, I believe when we initialize the client, we create an initial pool of sockets.

It is expected that most apps would only need one global client.

1 Comment

Java client has the option - minConnsPerNode - (default 0) - to keep some number of sockets always open. Helps when traffic is sparse - you don't incur the time overhead of creating a new socket when you get a transaction request. For continuous traffic, sockets stay around since they are discarded only after 55 sec idle time. As you rightly pointed, instantiating a client object is time consuming and is expected to be a "Singleton" for the life of an Application. Instantiating and destroying the client object for every database transaction is not the recommended way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.