On Monday of this week, we changed our webserver from gunicorn to Daphne to add support for websockets.
This morning we received a huge spike in db connections (>1000) causing errors of “FATAL: remaining connection slots are reserved for non-replication superuser connections”. We’re running our PostgreSQL database on AWS RDS and other than that period of time, there have generally been in the neighborhood of 18 connections. We did see a spike of some requests from ~500 requests per target to 1200 but that still doesn’t really line up with the runaway number of db connections.
I’ve seen several threads around connection pooling with ASGI servers and we are on Django 4.2 however we are using the default CONN_MAX_AGE, which I understand to be 0 and from similar threads my understanding has been that we shouldn’t have this problem.
We generally run 3 Daphne processes (with some autoscaling that can go up a couple), have a Celery worker + beat, and have a database with max_connections of 403.
Is there something else I’m missing or should we be thinking about adding something like PgBouncer, or upgrading to 5.1 to use connection pooling? Happy to provide more information if helpful