How to measure db connection time in Django? I am talking not about query, but about actual connection, before a query is made. It seems that db connection is done behind the scenes. Is there some way to surround the actual code of connection with timeit or similar code to estimate what time it takes to connect?
1 Answer
The connection usually stays alive within Django so it's not always that relevant.
But it also highly depends on the database server. To actually measure this you will need to (monkey)patch Django, my Django Statsd library has a few examples of how to measure things using Statsd: https://github.com/WoLpH/django-statsd
Alternatively you could create a custom database backend which incorporates some measurements. But connection timings (because of re-usage) is usually not relevant for Django.