Home > Mobile >  Couchbase connection pool
Couchbase connection pool

Time:10-07

I am building an application using couchbase as my primary db.
I want to make the application scalable enough to handle multiple requests at times concurrently.

How do you create connection pools for couchbase in Go?
Postgres has pgxpool.

CodePudding user response:

go-couchbase has already have a connection pool mechanism: conn_pool.go (even though there are a few issues linked to it, like issue 91).

You can see it tested in conn_pool_test.go, and in pools.go itself.

dnault points out in the comments to the more recent couchbase/gocb, which does have a Cluster instead of pool of connections.

CodePudding user response:

I'll give a bit more detail about how gocb works. Under the hood of gocb is another SDK called gocbcore (direct usage of gocbcore is not supported) which is a fully asynchronous API. Gocb provides a synchronous API over gocbcore as well as making the API quite a lot more user friendly.

What this means is that if you issue requests across multiple goroutines then you can get multiple requests written to the network at a time. This is effectively how the gocb bulk API works - https://github.com/couchbase/gocb/blob/master/collection_bulk.go. Both of these approaches are documented at https://docs.couchbase.com/go-sdk/current/howtos/concurrent-async-apis.html.

If you still don't get enough throughput then you can look at using one of these approaches alongside increasing the number of connections that the SDK makes to each node by using the kv_pool_size query string option in your connection string, i.e. couchbases://10.112.212.101?kv_pool_size=2 however I'd recommend only changing this if the above approaches are not providing the throughput that you need. The SDK is designed to be highly performant anyway.

  • Related