I’m working on Couchbase performance issues and learning a lot the painful way. Therefore, I would like to share my finding within this blog post. Hopefully, this will be helpful for someone taking the same route.
This article targets people who are new to Couchbase and using the .net client.
At this point, I’m expecting that you have read some of the Couchbase docs. Couchbase.com has great docs and you can find great 101 articles online. For this post, I want to share some pitfalls when trying to include the Couchbase .Net client.
Bad examples = bad performance
I’ve started working with the code samples as shown on couchbase.com. However, the samples are responsible for performance issues.
Here a list of tips using the .net client:
- You shouldn’t create a bucket instance for every call. If a bucket is open, it can be used by multiple threads. Buckets are expensive object’s and therefore you should reuse them. The overhead for each OpenBucket call is high. OpenBucket opens the minimum number of connections as defined. In many cases, keeping a low min and bit higher max is ideal. This because the client can tune itself.
- Make sure to make buckets static and long-lived.
- For web apps, create and open the bucket from within Application_Start. The Cachehelper makes this process simpler. The downside is that Cachehelper supports one cluster.
- Use ClusterHelper.OpenBucket which maintains the bucket instance.
- Use the Couchbase session provider to store session data.
memcached VS Couchbase buckets
This is important! Make sure to know the difference between the two. In general, memcached buckets perform better. However, this is only true when you store items shorter than 30 minutes. In addition, replication and rebalancing option aren’t supported.
memcached buckets don’t have a persistence layer. Because of this, the least frequent accessed times are deleted when creating new keys.
memcached buckets use a different storage system based on slabs. memcache allocates space in chunks on demand. This process can be inefficient depending on your caching strategy. You can find detailed information within this article
My advice: stay away from memcached buckets unless you know what you are doing.
- Don’t outsmart the client regarding connection pooling. Couchbase uses connection pooling internal. Adding additional pooling logic isn’t needed.
- Make sure to configure connection pooling. The defaults are suitable for developer and tests environments. If you run out of connections the client will throw an “ConnectionUnavailable” exception. Therefore make sure to monitor and adjust the maxSize value accordingly. This requires some tuning.
I hope this information is helpful for some. I’ve listed the resources I’ve used in the section below. In case you have any questions, please leave a comment below.