Django is taking a long time to load

Question:

For some reason, Django just started taking a really long time to load.

When running python manage.py runserverit takes about 30 seconds for the server to run. But everything looks normal.

Watching for file changes with StatReloader 
Performing system checks... 

System check identified no issues (0 silenced). 
March 12, 2020 - 19:59:26 
Django version 3.0.3, using settings 'navio.settings' 
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

And after, every page takes about 22 seconds to load.

Any clue about what is happening? The only thing I did before this happened was creating and then deleting a file called templatetags.py.

Asked By: overclock

||

Answers:

As an option you can install django-debug-toolbar to check CPU/DB time and find a long running query, if that’s a problem.
Another option is to profile django app. Here are some articles you may want to read.

If this is production app, you can check for Newrelic for a trial period.

Possible reasons are:

  • long running queries
  • requests to external servises, that respond with noticible delay (or fail after timeout)
  • insufficient system resourses
  • many other things
Answered By: Charnel

I had the same problem, restarting the computer fixed it.

Answered By: Chidem S

Something to ask is are doing any processing of your assets?
I was very stupidly running npx instead of npm when in debug mode to install a freshly minified version. npx runs a npm package without installing it, which means everytime before it runs, it downloads the package, run the commands, then cleans up after itself… all in about 3seconds per command.

Answered By: run_the_race

If anyone googles this, make sure that any of the classes you have don’t have an intensive function call in __init__.

I also recommend using django debug toolbar.

https://pypi.org/project/django-debug-toolbar/

Answered By: vcm
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.