4

每当我运行 python manage.py runserver 并在浏览器中使用 localhost:8000 访问我的网站时,第一个请求非常慢(大约 10 秒)。

以下请求真的很快。有什么办法可以提高它的性能吗?这非常不方便,因为在开发过程中,由于代码更新,它总是重新加载。

非常感谢。

4

4 回答 4

3

runserver如果你开始而0.0.0.0不是127.0.0.1因为它必须解决一些奇怪的路由接口循环,你会遇到这种问题。

于 2020-05-11T15:07:14.393 回答
1

Does this happen to empty Django project (freshly generated) or just for your specific site?

Without having more specific information it is hard to tell why.

The first request most likely lazily initializes some data. It could e.g. call external websites to get data and is slow due to bad DNS or slow Internet connection. Alternative, caches are empty and they are repopulated on the startup of the Django development server.

于 2015-01-11T01:06:30.433 回答
0

使用django-debug-toolbar,django-debug-toolbar 是一个非常方便的工具,可以深入了解您的代码正在做什么以及花费了多少时间。特别是它可以向您显示您的页面正在生成的所有 SQL 查询,以及每个查询花费了多长时间。

于 2016-08-24T12:38:10.943 回答
-6

找到了,将数据发送到远程监控服务的中间件。解决方案是仅在生产服务器上而不是在开发服务器上激活它!

于 2015-01-11T20:46:29.397 回答