3

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 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.