如何防止 mod_wsgi django 应用程序重复重新加载?

发布于 2024-09-05 15:50:29 字数 201 浏览 3 评论 0原文

我的 mod_wsgi django 应用程序似乎在客户端发出的前几个请求中不断重新加载。这正在扼杀我的性能

在足够的请求之后,它似乎稳定下来,并且应用程序似乎不再重新加载。关于为什么会发生这种情况以及如何预防它有什么想法吗?

(我在httpd.conf中有以下内容:MaxRequestsPerChild 0,所以不是这样的)

My mod_wsgi django application seems to keep getting reloaded for the first several requests that the client makes. This is killing my performance

After enough requests it seems to settle down, and the application no longer seems to be getting reloaded. Any thoughts on why this is happening and how I can prevent it?

(I have the following in httpd.conf:MaxRequestsPerChild 0, so that isn't it)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖伴 2024-09-12 15:50:29

这可能是因为您在 UNIX 系统上使用 mod_wsgi 和 Apache 的嵌入模式,甚至可能使用 Apache prefork MPM,这会使情况变得更糟。简而言之,在该配置中 Apache 它是一个多进程 Web 服务器。结合默认情况下在第一个请求时延迟加载应用程序的事实,您将看到在应用程序加载时针对每个 Apache 服务器子进程的初始请求出现延迟。

即使对于 Django 框架,这也不应该过多,并且会质疑您的特定应用程序在启动时正在做什么,从而导致长时间延迟或大负载峰值。

要了解这些问题,请务必阅读:

http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html
http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading

然后更改为使用 mod_wsgi 的守护进程模式,如 mod_wsgi wiki 页面上所述。特别是从以下位置开始:

http://code.google.com/p/modwsgi/wiki/ QuickConfigurationGuide

如果确实需要运行多个守护进程,而不仅仅是希望应用程序将获得哪种负载,并且加载时间仍然是一个问题,那么您可以配置 mod_wsgi使用 WSGIImportScript 和其他方法在进程启动时在任何请求进入之前预加载 WSGI 应用程序。不过对于 Django,请确保使用以下描述的 WSGI 脚本文件:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use- with.html

而不是 Django 文档描述的那个,因为它延迟加载,您仍然可以看到问题以及 WSGI 托管机制和内置开发服务器之间的行为差​​异。

This is likely because you are using embedded mode of mod_wsgi and Apache on a UNIX system, possibly even with Apache prefork MPM which makes it all worse. In short, in that configuration Apache it is a multi process web server. Combine that with fact that default is to lazily load application on first request, you will see a delay on initial request against each Apache server child process as application loads.

Even for Django framework this shouldn't be excessive and would question what your specific application is doing on startup to cause a long delay or large load spike.

To understand the issues, make sure you read:

http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html
http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading

Then change to use daemon mode of mod_wsgi instead as documented on mod_wsgi wiki pages. In particular start with:

http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide

If it is truly warranted that you need to run more than one daemon process and not just being hopeful about what sort of load your application is going to get, and load time is still a concern, then you can configure mod_wsgi using WSGIImportScript and other methods to preload your WSGI application at process start before any requests come in. For Django though, make sure you use WSGI script file described in:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

and not the one that Django documentation describes as it lazily loads and you can still see problem as well as differences in behaviour between WSGI hosting mechanisms and built in development server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文