Couchbase connection tuning in SDK 2



I have a question about CouchbaseEnvironment. According to the documentation, we should share the resource but how do you connect to the same cluster with different settings constraints (timeout, pool, connections) ?

For example, imagine that you need low timeout on reading in a part of the application and you need higher timeout for bulk writing in an other part.

Do you have a solution ?


Hi @cnguyen,

If you need to completely go custom you can create many environments but then you should share the ioPool and the computationPool (since those are the expensive ones). This is quite advanced though, if it’s just about timeouts I recommend you to just use all the method overloads with custom timeouts.

Which settings do you want to tweak exactly?


Hi @daschl,

I want to customize kvTimeout but i would be able to have different values for read and write.
Maybe i should keep the default kvTimeout and only overload method as you said.


@cnguyen in this case definitely… just use the overloads provided for any method with your custom timeouts, using a completely new environment is overkill :smile:


Ok, thank you for your advice @daschl :wink:


There are not many use cases to really use two different environments in one JVM (this is why we abstracted it away from the Cluster so you can reuse it in the first place). For example if you connect to multiple clusters and you want total isolation of thread pools and there like because one should not starve the other - but then in reality it’s just one JVM with shared resources…