Connection Pools needed for Couchbase ?
Hello;
I am evaluating Couchbase and follow examples of the JAVA SDK to try out get and set with Couchbase.
To get a CouchbaseClient I use the method
//First I got a CouchbaseClient
couchbaseClient = new CouchbaseClient(URI_LIST,"default", "");
//Than I get some values form Couchbase
CASValue userAccountCASValue
= couchbaseClient.gets(usersAccountDocumentKey, USERS_ACCOUNT_TRANSCODER);
//Than I shutdown the couchbaseClient
couchbaseClient.shutdown(SHUT_DOWN_WAIT_TIME, TimeUnit.SECONDS);
Now in the real system, this is type of process is going to be done with very high concurrency, about 100K per second.
My question is,
is
couchbaseClient = new CouchbaseClient(URI_LIST,"default", "");
and the corresponding
couchbaseClient.shutdown(SHUT_DOWN_WAIT_TIME, TimeUnit.SECONDS);
Expansive to execute.
Should the CouchbaseClient be cached somewhere for reuse ?
In SQL database, creation of a connection is expansive and often there are connection pools to reuse
the connection.
Is there equivalent consideration for Couchbase ?
Will the high concurrent, creating and shutting down a CouchbaseClient a concern ?
Any pointers or reference to this matter will be most appreciated.
Hi,
thanks for raising this!
Actually its quite simple: Initializing the client takes time, so make sure to do it only once (or as less as possible). You don't need to have connection pools, because the client itself handles all connections for you (and they depend on the amount of servers you have in the cluster).
So, make sure to connect during startup (for example in a context listener on servlets) and reuse the connection. Since everything happens asynchronously, as long as you dont wait for the futures to finish, you can work with the client commands in a nonblocking fashion. A common pattern is to use a singleton object to return the connected instance (if you need a controlled way to share your object).
Does this answer your question or do you need any specific advise?