Low performance when I call GetDocument by concurrent Request

My business is like below:

.Net Client(WinFrom Application) send request to a Socket Server (implement by IOCP), and when each request was received in Socket Server side, then Server will get the document from Couchbase. But I found that there is a low performance. At first, It only 1~2 request can be processed in Server side, Some time later the performance was increased, and it will be faster and faster.

If without get document from Couchbase, Socket Server will process 10000+ request per second.

It is my code:

      public class CouchbaseAccess
            private static string _server = string.Empty;
            private static string _bucketName = string.Empty;
            private static string _userName = string.Empty;
            private static string _password = string.Empty;
            private static IBucket _bucket = null;
            static CouchbaseAccess()
                _server = "";
                _bucketName = "default";
                _userName = "";
                _password = "";
            public static void Initialize()
                var config = new ClientConfiguration();

                config.Servers = new List<Uri>(new Uri[] { new Uri(_server) });

                    new BucketConfiguration
                        BucketName = _bucketName,
                        Username = _userName,
                        Password = _password,
                        PoolConfiguration = new PoolConfiguration
                            MaxSize = 5,
                            MinSize = 2,
                            SendTimeout = 12000,
                            BufferSize = 1024


                _bucket = Bucket();
            private static CouchbaseAccess instance = null;
            public static CouchbaseAccess Instance
                    if (instance == null)
                        instance = new CouchbaseAccess();
                    return instance;

            public static IBucket Bucket()
                return ClusterHelper.GetBucket(_bucketName);

            public static IBucket Bucket(string bucketName)
                return ClusterHelper.GetBucket(bucketName);

            public IOperationResult<byte[]> Get(string key)
                return _bucket.Get<byte[]>(key);

            public byte[] GetDocument(string key)
                IDocumentResult<byte[]> documentResult = _bucket.GetDocument<byte[]>(key);
                return documentResult.Content;

Cloud you please can help me out?
Thank you in advance


I would try one of these two things, or both.

  1. Increase the number of connections in your connection pool. When you first connect to the bucket, it will open only the minimum number. As there is demand, this will increase up to the maximum number of connections. That might explain your gradual increase in throughput.

  2. Turn on multiplex IO in your configuration (http://blog.couchbase.com/2016/january/couchbase-.net-sdk-2.2.4-now-available). This will allow more than one request down a single connection while waiting on responses to earlier requests.

Either of these should help improve your throughput.



@windyliupei -

I would leave the BufferSize to the default 16k. Reducing the buffer size just means you’ll spend more time/loops reading/writing.

If none of these things improve performance, we’ll need to dig deeper.


Many thanks, I have resolved my issue, base on your 2nd suggestion. It is works for me.


The solution : “IO Multiplexing” is works for me, So I just use this function.

Anyway, Thank you for your reply.

1 Like