Back to Blogs

Performance: Managing threads in Couchbase 2.x

Kirk Kirkconnell of Couchbase Published

In this blog post you will get an overview of two related performance optimizations that you can do for Couchbase 2.5.1 and below. This is not for 3.x for reasons you can read at the bottom of this post. The two changes directly effect performance of reading and writing in Couchbase. Also know that you must have a properly sized cluster before you start messing with these settings. If you do not, you may cause more problems for the cluster than you solve. If you need more information about sizing your cluster, please see Perry's execellent blog series on the topic.

Adding More Reader/Writer Threads Per Bucket

The first is changing the number of threads available on a per bucket basis. This should only be done if you have enough server/instance resources for this. If you are runing only 4 cores on your Couchbase nodes, this is probably not the performance enhancement for you. This setting will allow Couchbase to use more reader/writer threads and thus push more operations. So in the configuration of each bucket you will see a part of that screen that looks like this:

Optimizing More for Mixed Usage or Write heavy workloads

The second optimization links in with the first one. It has to do with optimizing Couchbase for either reading, writing or both. By default, Couchbase is optimized for reading thread wise and for many use cases, that works great. If you have mixed or a write heavy use case, you want to optimize Couchbase for that. You change these values with a REST API call like below with wget:

wget -O- --user=<admin user> --password=<password> --post-data='ns_bucket:update_bucket_props("<bucket name>", [{extra_config_string, "workload_optimization=mix"}]).' http://localhost:8091/diag/eval

The third option is to weight the threads towards writers:

wget -O- --user=<admin user> --password=<password> --post-data='ns_bucket:update_bucket_props("<bucket name>", [{extra_config_string, "workload_optimization=write"}]).' http://localhost:8091/diag/eval

If you want to set this back to the default, you'd do:

wget -O- --user=<admin user> --password=<password> --post-data='ns_bucket:update_bucket_props("<bucket name>", [{extra_config_string, "workload_optimization=read"}]).' http://localhost:8091/diag/eval

Note: All of the changes above REQUIRE a restart of the bucket to take effect. This is one of the very few off-line operations in CB. So do not change this on your production cluster without a planned maintenance window and planned down time!! For the changing of the number of threads, Couchbase will do that bucket restart for you once save it. For the REST calls, you will have to do it manually. Either way, plan appropriately for the down time!

For more information on this see the official documentation.

Is this still necessary for Couchbase 3.0?

No. These optimizations are no longer necessary in 3.x because of the introduction of a feature called the Global Thread Pool. With that feature, Couchbase now manages the the number of threads and the balance of threads dynamically for you and with intelligence as to your workload.

«   Back to blogs