35 ms·
Can anyone recommend a Django connection pool for MySQL that -- and this is the important part -- closes local pool connections to the database on a routine bas
by jeremyw 14y ago
Can anyone recommend a Django connection pool for MySQL that -- and this is the important part -- closes local pool connections to the database on a routine basis.
Reason: load balancers and machine maintenance. In per-connection mode (i.e. no connection pooling), operations folk can take machines out for service quickly: put the box in MAINT (ala HAProxy) or equivalent, wait a few moments, see the connections drain away to zero.
But I haven't been able to find connection pooling logic that recycles backend sockets on a short basis. For instance, 60s is long enough to amortize the cost of connection setup, but short enough to make your operations people very happy.
- zzzeek 14y agoseems like I'll have to reply to every post on this thread but sqlalchemy's pool does this, either optimistically or pessimistically, see http://docs.sqlalchemy.org/en/rel_0_8/core/pooling.html#dealing-with-disconnects http://docs.sqlalchemy.org/en/rel_0_8/core/pooling.html#deal... (in particular pool_recycle).
- jeremyw 14y agoYes, SQLAlchemy is excellent in this respect, but without getting into a Django ORM vs SQLAlchemy debate, it is the less-preferred option among Django developers.
- zzzeek 14y agothe pool can be used in isolation of the rest of SQLAlchemy, which is what Kenneth's Django-Pool library is doing.
- est 14y agoI think Django db connection are doing it plain wrong. Connection are established and gone with a request, but in fact we can simply use a global variable for any SQL/NoSQL connection pool in views.py, which is basically a WSGI global variable. In this case, connections are established when a gunicorn/uWSGI worker process starts, and shutdown when the worker is respawned.
- jeremyw 14y agoRight, the problem is all the failure modes. You want a battle-tested library that hands you a valid connection, that will work to the 99th percentile. Lots of edge cases.