vintasoftware / django-react-boilerplate

Django 5, React, Bootstrap 5 with Python 3 and Webpack project boilerplate
MIT License
1.97k stars 479 forks source link

Set Persistent Connections to a low value by default #558

Open fjsj opened 2 years ago

fjsj commented 2 years ago

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

gabicavalcante commented 2 years ago

@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 commented 2 years ago

@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.