News for hackers. Stuff that matters.
Re:Fixing Database Connections in Django by jeremyw on Friday March 08, 2013 @04:15PM (#5345774)
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.

Re:Fixing Database Connections in Django by zzzeek on Friday March 08, 2013 @05:18PM (#5346107)
seems 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#deal... (in particular pool_recycle).
Re:Fixing Database Connections in Django by jeremyw on Friday March 08, 2013 @05:55PM (#5346295)
Yes, 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.
Re:Fixing Database Connections in Django by zzzeek on Friday March 08, 2013 @06:11PM (#5346374)
the pool can be used in isolation of the rest of SQLAlchemy, which is what Kenneth's Django-Pool library is doing.
Re:Fixing Database Connections in Django by est on Saturday March 09, 2013 @12:40AM (#5347523)
I 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.

Re:Fixing Database Connections in Django by jeremyw on Saturday March 09, 2013 @12:44AM (#5347532)
Right, 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.
Re:Fixing Database Connections in Django by est on Saturday March 09, 2013 @01:52AM (#5347663)
Django's connection is a battle-tested failure.
Re:Fixing Database Connections in Django by jeremyw on Saturday March 09, 2013 @05:27PM (#5349844)
Connection-per-request is battle-tested. Other scenarios, what we're discussing, are not.