Yeah, we found the ping() during performance profiling too. It's a
significant performance hit -- it basically doubles the number of
requests to the DB server. It seems that the reason is to support use
cases where the DB connection is long-lived, since sometimes DB
connections die if you leave them open for a really long time. In the
normal Django HTTP request use case this never happens because Django
closes the DB connection at the end of each request. But it could
potentially be useful for people who use django.db in some other
custom process.
We ended up commenting out the ping() stuff so that any opened
connection was always treated as valid.
It seems to me that the performance overhead in the 99% use case would
suggest that it would be beneficial for Django to let users configure
whether or not their DB connection constantly pings or not. Or maybe
just keep track of the time and don't ping unless some minimum time
has elapsed since the last one. Or do what we did, and just don't ping
at all and let the app deal with the case where the DB drops the
connection.
-Jesse