Django dev server extremely slow

1.7k views Asked by At

We have an app that works perfectly fine on production but very slow on the dev machine.

Django==2.2.4

I'm using Ubuntu 20.04 but other devs are using macOS and even Windows.

Our production server is a very small compared to the dev laptops (it works very slow on every dev environment, we are 5 developers).

The app makes several request since it's a Single Page application that uses Django Rest Framework and React.js in the front-end.

We have tried different databases locally (currently postgresql, tried MySQL and sqlite3), using docker, no docker, but it does not change the performance.

Each individual request takes a few seconds to execute, but when they go all toghether the thing gets very slow. As more request are executed, the performance starts to drop.

It takes the app between 2/3 minutes to load in the dev environment and in any production or staging environment it takes little above 10 seconds.

Also tried disabling DEBUG in the back and front-end, nothing changes.

It is my opinion that one of the causes is that the dev server is single thread and it does not process a request until the previous is finished. This makes the dev environemnt very hard to work with.

I've seen alternatives (plugins) to make the dev server multi-thread but those solutions do not work with the latests versions of django.

What alternatives could we try to improve this?

1

There are 1 answers

0
user1532587 On

Looks like posting this question helped me think in an alternative. Using gunicorn in the dev environment really helps.

Installed it with

pip install gunicorn

And then execute it using this:

venv/bin/gunicorn  be-app.wsgi --access-logfile - --workers 2 --bind localhost:8000 

Of course if I want to access the static and media files I'll have to set up a local nginx but it's not a big deal