nickjj / docker-django-example

A production ready example Django app that's using Docker and Docker Compose.
MIT License
1.17k stars 249 forks source link

Connection Pooling for Django Project #2

Open Keda87 opened 3 years ago

Keda87 commented 3 years ago

Hi @nickjj, thank you for making this repository. I would have a look at this repo for my reference. I'm looking for a Django project example that uses connection pooling (pgbouncer or pgpool) but seems like this repo does not use this.

My concern is because Django's DB connection is created during the request and closed after returns the response. this based on the documentation https://docs.djangoproject.com/en/3.2/ref/databases/#general-notes

I think using connection pooling would make this project better for production-ready project reference.

Thank you in advance

nickjj commented 3 years ago

Hi,

Have you run into a scenario where not using pgbouncer resulted in issues? Do you have an example of a configuration for it that's been known to work with a before / after comparison?

Keda87 commented 3 years ago

Ohh ya, not yet for now. Will get back to you after I create a load test result.

55nevets commented 2 years ago

I'm interested in this too. I don't see this in the django-cookiecutter setup either so maybe not that important?

nickjj commented 2 years ago

There's pros and cons. I'm not a DBA but my surface level understanding is for single threaded applications (such as running gunicorn with 1 thread and X workers) DB pooling may slow things down.

Realistically I can only trust the results I've seen in production. I've had single low powered servers happily serve hundreds of thousands of requests per month in Flask apps. DB connections weren't a bottleneck. Flask is similar enough to this Django app, both frameworks are using gunicorn with PostgreSQL using the psycopg2 package.

I've never operated a site that receives hundreds of millions of daily requests. Maybe it's an issue then, my philosophy around that is I'll figure it out when it happens instead of trying to optimize for it now where it looks like it would provide worse results.