Report this

What is the reason for this report?

Configuring gunicorn workers on App Platform with Django

Posted on September 7, 2023

I’m running DRF as my backend, connecting to Postgres. I’m running out of DB connections at times (with not much traffic) and I’m trying to optimize settings. Some advice that I’ve gotten:

  • configure gunicorn to 3-4 workers
  • use persistent connections (Django setting)
  • Use CONN_HEALTH_CHECKS=True in Django settings - I can’t acutally do this one yet, as I’m not on Django 4.1 yet

I’m having trouble with the first item. Some tutorials (https://docs.digitalocean.com/developer-center/deploy-a-django-app-on-app-platform/#step-4-deploying-to-digitalocean-with-app-platform) show a run command like gunicorn --worker-tmp-dir /dev/shm django_app.wsgi, and I could add the worker count option here, but gunicorn isn’t found during the deployment, so now I’m dubious that it’s even being used.

My primary question is how to set the number of workers for gunicorn on Django with App Platform, but if you have other advice for not running out of DB connections with Django, I’m allllll ears!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.