为什么 mod_python 从每个请求开始就运行整个 django 堆栈?
我的理解是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如其他人指出的那样,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.
每个 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.