Connection pooling in Couchbase SDK (spymemcached)

We are in process of evaluating couchbase. Following are the list of questions with reference to couchbase.

1) Does the couchbase client has internal connection pooling concept ? If yes, how can we tune the connection pool ? If not, can someone provide a sample code to develop connection pooling ?
2) It is mentioned that CouchbaseClient is thread-safe.

How many concurrent thread it can serve ? What is the upper limit for thread pool for accessing the client object concurrently ?

Regards,
Gaurav Shah.

2 Answers

« Back to question.

Hello,

Couchbase SDKs are thread safe and for Java and .Net, you can use without developing your own pool.

In Java, just create a singleton that initialize the connection to the cluster at startup then get the connection whenever you need it.

You can take a look to the BeerSample Application :
See the ServletContextListener:
https://github.com/couchbaselabs/beersample-java/blob/master/src/main/ja...

And how to get a connection for example in a servlet:
https://github.com/couchbaselabs/beersample-java/blob/master/src/main/ja...

Regards

« Back to question.

Gaurav:

Connection pooling is not required. You can tune some of the parameters in the Couchbase connection, however,
via the CouchbaseConnectionFactoryBuilder class. Please refer to

http://www.couchbase.com/wiki/display/couchbase/Couchbase+Java+Client+Li...

Yes, the CouchbaseClient is thread safe. There is no upper limit from a Couchbase connection perspective.

Thanks!
Rags

Thanks Rags for the reply .... !

I was looking into code implementation and notice that couchbase makes a single SocketChannel connection to server (node). I mean one SocketChannel connection per node.

While referring to javavdoc of SocketChannel, it specifies that :
Socket channels are safe for use by multiple concurrent threads. They support concurrent reading and writing, though at most one thread may be reading and at most one thread may be writing at any given time. The connect and finishConnect methods are mutually synchronized against each other, and an attempt to initiate a read or write operation while an invocation of one of these methods is in progress will block until that invocation is complete.

I inferred this statement as all the request to the server are queued up and one single socket connection is made and then sequentially requested is served. i.e. one at a time.

Lets take a scenario either my network is slow or the amount for request generated during bulk load / bulk access is too high as compare to the rate at which it is served. The requested is queued up at couchbase client level (ReadOperationQueue,WriteOperationQueue,OperationQueue, etc) followed by requested queued up at SocketChannel level.

Coming back to my original question, do we require custom connection pool in order to create multiple socket connection to same server. Only concern is that we are making only one physical socket connection with server thus wanted to understand that will it cause a bottleneck or not.

Kindly point out in case my interpretation is incorrect.

Regards,
Gaurav Shah.

You are right about the internal workings of the Java client library. These operations are meant to be low latency operations and since they are asynchronous in nature the queueing should not be an issue. So, still of the opinion that connection pooling is not required.

Thanks!
Rags