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 runserver
it 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
.
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
I had the same problem, restarting the computer fixed it.
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.
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.
For some reason, Django just started taking a really long time to load.
When running python manage.py runserver
it 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
.
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
I had the same problem, restarting the computer fixed it.
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.
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.