Uwsgi + Flask +Couchbase


#1

Dear all,

I’m using uwsgi to deploy Flask application.
When im spawn several flask applications as processes, i notice that only one db connection is created so when im doing benchmark on simple bucket.get() it throws exception write down below.

couchbase.exceptions._TimeoutError_0x17 (generated, catch TimeoutError): <Key=‘995577400398’, RC=0x17[Client-Side timeout exceeded for operation. Inspect network conditions or increase the timeout], Operational Error, Results=1, C Source=(src/multiresult.c,316), Tracing Output={“995577400398”: null}>

Can you suggest to do something, or how can i create one db connection per flask app.


#2

Hi @asakurajano, have you tried increasing the timeout using the Bucket.timeout property?

Bucket instances are not multithread capable, so you need to either create new Bucket connections for each thread. This is possibly why you are seeing timeouts, as one call is blocking another - the Python client locks the libcouchbase instance until any call has returned from LCB. An alternative is to use an async API (txcouchbase or acouchbase, for example).

Hope that helps,

Thanks,

Ellis


#3

Thank you for reply,

By default uwsgi spams workers in such logic:
It creates master process with db connection and than forks(copies) processes , so connection is only one for several process.

There is configuration parameter lazy-app = true which will create new connection on every process.