Django's dev server causes permanent high CPU load with Python 3

4

Django's development server runs under Python 2.7.5 (on Windows 7) with a rather constant (idle) load of about 1-3% on my test system - no page loads or other calculations done. Switching to Python 3.4.2 causes the constant load to rise to an average of about 10%. That's pretty huge for not doing anything ... Is there any explanation for it? Can it be avoided? I tested this with various Django apps.

Simon Steinberger

Posted 2015-01-20T12:40:15.593

Reputation: 280

Answers

4

To answer my own question: Django's dev server checks all Python source files periodically for changes. Setting the option --noreload prevents this auto-restart mechanism, which also reduces the idle load to zero. Apparently, auto-reload on Python 3 is less efficient. Using pyinotiy is a solution for Linux to also prevent this overhead: https://docs.djangoproject.com/en/1.7/ref/django-admin/#runserver-port-or-address-port

Simon Steinberger

Posted 2015-01-20T12:40:15.593

Reputation: 280

2Just wanted to contribute that this was also what was causing the high CPU problem for me. Like Simon said adding --noreload to the runserver command solved it. Looks like the auto-reload in Django is incredibly wasteful; even without touching or modifying any .py file, they are reloaded constantly, causing really high CPU and I/O loads. – flatterino – 2017-08-21T13:50:12.420