Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Persistent Connections to a low value by default #558

Open
fjsj opened this issue Nov 27, 2021 · 2 comments
Open

Set Persistent Connections to a low value by default #558

fjsj opened this issue Nov 27, 2021 · 2 comments

Comments

@fjsj
Copy link
Member

fjsj commented Nov 27, 2021

https://docs.djangoproject.com/en/3.2/ref/databases/#persistent-database-connections

@gabicavalcante
Copy link

@fjsj the default CONN_MAX_AGE is 0, do you suggest any lower value?

The Heroku docs suggest 500s, the dj-database-url module recommend 600s, some other references recommend 60s.

We need to be careful because If the database terminates idle connections after some time we should set CONN_MAX_AGE to a lower value.

I also found a few issues related to persistent database connections with async workers on Django. If CONN_MAX_AGE != 0 (n or None), Django will reuse the connection (or opens it if it's closed) when needed BUT, apparently it doesn't necessarily close it at the end of requests. This problem doesn't happen with sync gunicorn workers.

@fjsj
Copy link
Member Author

fjsj commented Dec 24, 2021

@gabicavalcante One of our projects is using CONN_MAX_AGE = 600 w/o problem in production since last week.

We need to be careful because If the database terminates idle connections after some time we should set CONN_MAX_AGE to a lower value.

I think Django manages this well for us, so do you have other concerns?

I also found a few issues related to persistent database connections with async workers on Django.

I think eventlet is something very specific, and we don't use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants