Python SDK real world use
Tue, 01/01/2013 - 14:23
I'm trying to establish the correct method of using the Python SDK (as it stands right now) in a WSGI based application (Flask).
Each new connection to the cluster (single member running on localhost) takes over a second to establish. This means I must leave the connection open, which can then be reused by subsequent requests. I assume this is bad, as there are resources being left open after the WSGI process / thread dies (unless this is the rest client only?). I'm using the unified client at the moment.
I don't see an alternative to leaving this open right now (the unified client doesn't have a close method anyway). Any suggestions on the correct approach?
I can think of two approaches.
The best approach would be to keep this persistent across requests, and create it if it doesn't exist. Looking about a bit, I found one reference that says it should be possible to have this as a global dict[1]. This way, it would be around for the life of the process, and all of the resources would be collected after it's been used.
The second approach might be to implement a simple connection pool, as that seems to be a common recommendation I found with flask and django[2][3].
Well, there is a third approach, and that's that client side moxi can offload this. In that way, it's similar to pgpool or mysql proxy. The rest client and memcached client can be configured against a moxi running locally.
Longer term, we'll look to put something together for this, but we don't have anything at the moment. I'm interested in it personally.
Please let me know if you're able to get any further with the global approach.
1. http://stackoverflow.com/questions/6729639/how-to-share-db-connection-li...
2. http://dumpz.org/67550/
2. http://stackoverflow.com/questions/6688413/how-to-preserve-database-conn...