简体   繁体   English

Django 需要很长时间才能加载

[英]Django is taking a long time to load

For some reason, Django just started taking a really long time to load.出于某种原因,Django 刚开始需要很长时间才能加载。

When running python manage.py runserver it takes about 30 seconds for the server to run.运行python manage.py runserver时,服务器运行大约需要 30 秒。 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.之后,每个页面大约需要 22 秒才能加载。

Any clue about what is happening?关于发生了什么的任何线索? The only thing I did before this happened was creating and then deleting a file called templatetags.py .在这之前我唯一做的就是创建然后删除一个名为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.作为一个选项,您可以安装django-debug-toolbar来检查 CPU/DB 时间并查找长时间运行的查询,如果这是一个问题。 Another option is to profile django app.另一种选择是分析 django 应用程序。 Here are some articles you may want to read.这里有一些你可能想阅读的文章

If this is production app, you can check for Newrelic for a trial period.如果这是生产应用程序,您可以在试用期内检查Newrelic

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许多其他事情

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而不是npm 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. npx运行一个npm包而不安装它,这意味着每次在它运行之前,它都会下载包,运行命令,然后自行清理......每个命令大约需要 3 秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM