Connection pooling in Couchbase SDK (spymemcached)

Hi,
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 ocncept ? If yes, how can we tune the connection pool ? If not, can someone provide a sample code to write custom code.
  2. CouchbaseClient is thread-safe. How many concurrent thread it can serve ? What is the upper limit for no of thread accessing the client object concurrently ?
    Regards,
    Gaurav Shah.

hi Rags:
your comment about connection pooling not being necessary – does that hold true for specific versions of the Couchbase java client? In this document for 2.0 development, the author specifically suggests we implement connection pooling:
http://www.couchbase.com/docs/couchbase-devguide-2.0/threading-in-sdks.html
Note that the client object you create with a Couchbase SDK does not spawn additional threads to handle multiple requests. Therefore to provide multi-threading and client object reuse even for SDKs that are thread-safe, you will need to implement connection pools and other language-specific thread-safety measures. The following Couchbase SDKs are developed and tested as thread safe:
Java SDK 1.0 and above
.Net SDK 1.0 and above
thanks for any information.

thanks for the info, Tug.
curious if you guys have done any performance testing on the Couchbase Java Client (1.1.x)? I was curious to compare my results to any numbers you may have found. thanks.

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

Sorry for typos.
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.

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.

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

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

It sounds like in a highly concurrent environment, creating and managing a pool is still required. If I have 100 threads all trying to make a request at the same time, it could create a bottle neck for operations if even one thread blocks for a second. I noticed in the source ViewConnection.NUM_CONNS defines a maximum number of connections as 1, which seems strange to me. Is there a way to go above this limit without recompiling the code?