[Django]-First query in Django is always slow

3👍

Depending on the settings, the connection to the database might be closed after a request is finished. This is the case when CONN_MAX_AGE is set to 0. As a result, for each request, a new connection has to be set up.

You can for example set CONN_MAX_AGE to 60, such that you can reuse the connection that was opened by a previous request, and thus avoid this overhead. The very first query of your server might still be a bit slow, but the queries in the following requests will usually be faster.

Leave a comment