mod_wsgi 启动时速度过慢?

发布于 2024-08-23 13:08:44 字数 159 浏览 7 评论 0原文

我正在开发一个 django 网站,该网站使用 mod_wsgi 进行生产 - 几乎没有任何访问者,所以每次我访问时,mod wsgi 都会启动并打开 python 进程 - 完全加载大约需要 1-2 分钟。

我能做些什么来不让它在初始启动时变慢吗?这是一个常见问题还是只是我的配置问题?

I'm developing a django website which for production uses mod_wsgi - there are barely any visitors so anytime I visit it seems mod wsgi starts up and opens the python processes - it takes about 1-2 entire minutes for it to fully load.

Is there anything I could do to not make it slow on initial startup? Is this a common problem or could it just be an issue with my configuration?

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

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

发布评论

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

评论(2

等待圉鍢 2024-08-30 13:08:44

即使您使用嵌入模式和 Apache prefork MPM 的次优配置,也不应该花费那么长时间。不过,如果将 Apache 进程的 MaxRequestsPerChild 设置为 1,情况可能会变得更糟。

建议确保您使用 mod_wsgi 守护进程模式并使用单个多线程进程运行(WSGIDaemonProcess 的默认设置)。这将至少确保只有一个 Django 实例,而不是每个 Apache 服务器进程都有一个实例。

为了确认您正在做什么,请编辑您的问题并发布当前 Apache 配置的片段,显示如何设置 mod_wsgi 位。还包括您是否使用 Apache prefork 还是工作 MPM(可通过运行“httpd -V”确定)以及您正在使用的平台。

顺便说一句,您是否尝试过一个简单的 hello world WSGI 程序来验证您的安装?请参阅“http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide'。您是否尝试过使用一个空的 Django 站点(而不是您的真实站点)来看看这是否是您的更改?

It shouldn't take that long even if you used a suboptimal configuration of using embedded mode and Apache prefork MPM. Although, you could make things worse if you had MaxRequestsPerChild set to 1 for Apache processes.

Suggestions are, make sure you are using mod_wsgi daemon mode and run with a single multithreaded process (the default settings for WSGIDaemonProcess). This will ensure at least that there is only one instance of Django and not potentially one per Apache server process.

As confirmation of what you are doing, edit your question and post snippet of your current Apache configuration showing how to set up mod_wsgi bits. Include also whether you are using Apache prefork or worker MPM, determinable by running 'httpd -V' and what platform you are using.

BTW, have you tried a simple hello world WSGI program to validate your installation? See 'http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide'. And have you tried with an empty Django site, rather than your real one to see whether it is your changes?

ぶ宁プ宁ぶ 2024-08-30 13:08:44

只是对此有更多了解。您不想使用 prefork MPM 周期,这将导致每个预分叉进程产生 1x mod_wsgi 进程。

克服这个问题的最佳方法是使用工作 MPM 在守护进程模式下运行 WSGI 进程。

https://docs .djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode

编辑:

另请注意,您必须指定组,否则每个 HTTPD 进程似乎都会创建自己的组所有连接关闭后 mod_wsgi 进程。

WSGIScriptAlias / /usr/local/apache2/htdocs/ABC.com/build/wsgi.py
WSGIPass授权开启
WSGILazyInitialization 关闭
WSGIDaemonProcess ABC.com 用户=apache 组=apache 显示名称=%{GROUP} 进程=1 线程=256
WSGIProcessGroup ABC.com

Just some more light on this. You don't want to use prefork MPM period, it will cause 1x mod_wsgi process for each of the pre-forked processes.

The best way to overcome this is to run the WSGI process in Daemon mode with the worker MPM.

https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode

Edit:

Also note that you MUST specify the group otherwise each HTTPD process seemed to create its own mod_wsgi process after all the connections were closed.

WSGIScriptAlias / /usr/local/apache2/htdocs/ABC.com/build/wsgi.py
WSGIPassAuthorization On
WSGILazyInitialization Off
WSGIDaemonProcess ABC.com user=apache group=apache display-name=%{GROUP} processes=1 threads=256
WSGIProcessGroup ABC.com

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