在 mod_python 中终止单个 Apache 进程

发布于 2024-10-19 06:55:26 字数 564 浏览 6 评论 0原文

我们遇到了一个问题,个别 apache 进程根据请求使用大量内存,并且从不将其释放回主系统。由于这些请求可能随时发生,因此随着时间的推移,Web 服务器会被推入交换状态,甚至对 SSH 也会变得无响应。更糟糕的是,请求完成后,Python 无法将内存释放回原处,从而导致大量 500mb - 1gb Apache 进程闲置。

我们每秒推送的请求很少,但每个请求都可能非常繁重。

我想要做的是有一种方法可以在单个 apache 进程子进程完成服务请求后,如果其驻留内存超过某个阈值,则杀死它。我已经尝试了几种在 mod_python 中实际执行此操作的方法,但似乎任何形式的系统退出都会导致对客户端的响应无法完成。

每当这种情况发生时,除了优雅地处理所有进程(我们真正想要避免的)之外,是否有办法告诉 Apache 在完成请求服务后任意终止进程?欢迎所有想法。

需要额外注意的是,由于系统的遗留性质,我们无法升级到更高版本的 Python,因此我们无法利用 2.5 改进的内存性能。同样,我们也被当前的操作系统所困扰。

版本: 系统:红帽企业 4

Apache:2.0.55

Python:2.3.5

We are having a problem with individual apache processes utilizing large amounts of memory, depending on the request, and never releasing it back to the main system. Since these requests can happen at any time, over time the web server is pushed into swap, rendering it unresponsive even to SSH. Worse, after the request has finished, Python fails to release the memory back into the wild, which results in a number 500mb - 1gb Apache processes lying around.

We push very few requests per second, but each request has the potential to be very heavy.

What I would like to do is have a way to kill an individual apache process child after it has finished serving a request if its resident memory exceeds a certain threshold. I have tried several ways of actually doing this inside mod_python, but it appears that any form of system exit results in the response not completing to the client.

Outside of gracefuling all the processes (which we really want to avoid) whenever this happens, is there anyway to tell Apache to arbitrarily kill off a process after it has finished serving a request? All ideas are welcome.

As an additional caveat, due to the legacy nature of the system, we can’t upgrade to a later version of Python, so we can’t utilize the improved memory performance of 2.5. Similarly, we are stuck with our current OS.

Versions:
System: Red Hat Enterprise 4

Apache: 2.0.55

Python: 2.3.5

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

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

发布评论

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

评论(1

靑春怀旧 2024-10-26 06:55:26

我想说,即使有可能,这也将是一个巨大的黑客攻击(而且不稳定)——在这种情况下,您应该在 apache 外部设置一个进程,它将监督正在运行的进程并在超出内存时杀死单个 apache /时间预定义的限制。

这样的脚本可以通过主循环持续运行,主循环每隔几秒执行一次检查,甚至可以放入 crontab 中每分钟运行一次。

我认为没有理由尝试从服务流程本身内部进行此操作。

I'd say that even it is possible, it would be a tremendous hack (and instable) - you should set-up a process external to apache in this case, that would supervise running processes and kill an individual apache when it goes beyond memory/time predefined limits.

Such a script can be kept running continuously with a mainloop that is performs it's checks every few seconds, or could even be put in crontab to run every minute.

I see no reason to try to that from inside the serving processes themselves.

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