为什么 mod_python 从每个请求开始就运行整个 django 堆栈?

发布于 2024-09-17 16:33:01 字数 308 浏览 9 评论 0 原文

我的理解是 mod_python 将 python 进程加载到 apache 中,避免了每次调用时执行此操作的开销。我的期望是,这意味着我的 django 堆栈也只会加载一次。

然而,我观察到的是,每个请求从一开始就运行整个 django 堆栈,就好像它是第一个请求一样。设置被重新导入。中间件 __init__ 应该在 django 启动时运行一次,但每次都会运行。等等。它看起来基本上就像我所期望的 CGI 一样。

这是预期的行为吗?我主要使用 mod_wsgi,我相信它不能以这种方式工作,但我必须为当前的客户端使用 mod_python。

谢谢!

My understanding is that mod_python loads the python process into apache, avoiding the overhead of doing that on each call. My expectation was that this would mean that my django stack would also only be loaded once.

What I am observing, however, is that every request is running the entire django stack from the beginning, as though it were the first request. The settings are re-imported. Middleware __init__'s, which are supposed to be run once at django startup, are run each time. And so forth. It seems to be essentially like I would expect CGI to be.

Is this expected behavior? I have mostly worked with mod_wsgi, which I believe does not work this way, but I have to use mod_python for my current client.

Thanks!

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

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

发布评论

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

评论(2

哭了丶谁疼 2024-09-24 16:33:01

正如其他人指出的那样,UNIX 系统上的 Apache 是一个多进程系统。还要确保 Apache 配置中的 MaxRequestsPerChild 由于某种原因未设置为 1。理想情况下,该指令应设置为 0,这意味着保留进程,而不是根据请求数量回收它们。

Apache on UNIX systems is a multiprocess system as pointed out by someone else. Also make sure the MaxRequestsPerChild hasn't been set to be 1 in Apache configuration for some reason. Ideally that directive should be set to 0, meaning keep processes around and not recycle them based on number of requests.

蝶舞 2024-09-24 16:33:01

每个 httpd 进程都会加载 Django 一次。由于多个进程启动(每个子进程都是一个进程),因此启动了多个 Django 实例。

It loads Django once per httpd process. Since multiple processes start (each child being a process), multiple instances of Django are started.

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