I try to connect to a Bucket in thread using LOCKMODE_WAIT
and 60 seconds operation timeout. While it can connect and read/write data just fine, the connection doesn’t seems to be closed.
Connection is created using
self.cache = Bucket('couchbase://{host}/{bucket}?operation_timeout=60'.format(
host=setting.CONFIG_COUCHBASE,
bucket=bucket),
lockmode=LOCKMODE_WAIT)
See the following graph, the flat part is when I don’t use connection in thread. During this time, we have rather stable incoming traffic as well.
The scenario for this is that I’m using Bucket connection on REST API. For every request comes in, I use one Bucket connection on main thread for caching. Then another thread creating a separate connection to the same bucket for caching different data. So every request should only create 2 instances of Bucket connection in total.
As number of connections grows, so does memory of my API. What’s the best way to use Couchbase on threaded environment? Should I not do that at all?
I did read http://pythonhosted.org/couchbase/ document on Threads but I don’t totally understand the explaination.
Any idea what I should take a look at?