睡觉的PHP进程(mod_fcgid)快速恢复RAM

时间:2022-10-06 08:08:06

I hope that this is the right place to ask this question, so:

我希望这是提出这个问题的正确位置,所以:

We are running a Debian (virtualized) server with Apache running php as fcgi. Today the administrator told me that the processes are consuming the RAM on the system. He asked me to look around my code.

我们正在运行一个Debian(虚拟化)服务器,Apache运行php作为fcgi。今天管理员告诉我,进程正在消耗系统上的RAM。他让我看看我的代码。

Well I think that virtually I have no control over the php processes since Apache spawns them, so this seems more like a server configuration problem. It seems that every request spawns a new php process (this is ok). After my script terminates the php process goes to sleep.

好吧,我认为实际上我无法控制php进程,因为Apache会产生它们,所以这看起来更像是服务器配置问题。似乎每个请求都会生成一个新的php进程(这没关系)。我的脚本终止后,php进程进入休眠状态。

This is what top looks like. I sorted by memory and these are the php processes (they run on the user edem):

这是顶部的样子。我按内存排序,这些是php进程(它们运行在用户edem上):

top - 14:49:35 up 41 days,  2:09,  2 users,  load average: 0.16, 0.13, 0.06
Tasks: 228 total,   1 running, 227 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.7%us,  0.3%sy,  0.0%ni, 98.7%id,  0.0%wa,  0.0%hi,  0.3%si,  0.0%st

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                           
12358 edem      20   0 67380 6464 2976 S  0.3  0.2   0:00.06 php                                                                                                                                               
12250 edem      20   0 66960 9776 6584 S  0.0  0.3   0:00.11 php                                                                                                                                               
12253 edem      20   0 67480 7812 3832 S  0.0  0.3   0:00.19 php                                                                                                                                               
12254 edem      20   0 67464 7108 3316 S  0.0  0.2   0:00.07 php                                                                                                                                               
12255 edem      20   0 67404 7340 3604 S  0.0  0.2   0:00.14 php                                                                                                                                               
12256 edem      20   0 67464 7128 3336 S  0.0  0.2   0:00.07 php                                                                                                                                               
12257 edem      20   0 67380 6484 3000 S  0.0  0.2   0:00.04 php                                                                                                                                               
12258 edem      20   0 67464 7092 3312 S  0.0  0.2   0:00.05 php                                                                                                                                               
12259 edem      20   0 67464 7184 3392 S  0.0  0.2   0:00.07 php                                                                                                                                               
12260 edem      20   0 67464 7088 3296 S  0.0  0.2   0:00.06 php                                                                                                                                               
12263 edem      20   0 66960 9780 6584 S  0.0  0.3   0:00.11 php                                                                                                                                               
12265 edem      20   0 67464 7084 3280 S  0.0  0.2   0:00.09 php                                                                                                                                               
12266 edem      20   0 67436 7376 3600 S  0.0  0.2   0:00.14 php                                                                                                                                               
12267 edem      20   0 67464 7144 3340 S  0.0  0.2   0:00.06 php                                                                                                                                               
12268 edem      20   0 67380 6508 3016 S  0.0  0.2   0:00.05 php                                                                                                                                               
12269 edem      20   0 67540 7672 3820 S  0.0  0.2   0:00.22 php                                                                                                                                               
12270 edem      20   0 67496 6488 3040 S  0.0  0.2   0:00.05 php                                                                                                                                               
12271 edem      20   0 67436 7372 3596 S  0.0  0.2   0:00.15 php                                                                                                                                               
12272 edem      20   0 67464 7108 3304 S  0.0  0.2   0:00.07 php                                                                                                                                               
12277 edem      20   0 66960 9776 6584 S  0.0  0.3   0:00.11 php                                                                                                                                               
12279 edem      20   0 67436 7368 3596 S  0.0  0.2   0:00.15 php                                                                                                                                               
12280 edem      20   0 67464 7096 3296 S  0.0  0.2   0:00.07 php                                                                                                                                               
12281 edem      20   0 67464 7748 3808 S  0.0  0.2   0:00.18 php                                                                                                                                               
12282 edem      20   0 67496 7388 3600 S  0.0  0.2   0:00.14 php                                                                                                                                               
12283 edem      20   0 67380 6464 2976 S  0.0  0.2   0:00.04 php                                                                                                                                               
12284 edem      20   0 67380 6464 2976 S  0.0  0.2   0:00.05 php                                                                                                                                               
12285 edem      20   0 67464 7168 3368 S  0.0  0.2   0:00.07 php                                                                                                                                               
12286 edem      20   0 67464 7104 3304 S  0.0  0.2   0:00.06 php                                                                                                                                               
12287 edem      20   0 66960 9780 6584 S  0.0  0.3   0:00.11 php                                                                                                                                               
12289 edem      20   0 67464 7140 3336 S  0.0  0.2   0:00.07 php   

Do you have any ide how to kill those sleeping (idling) php processes? Is there something I'm doing wrong?

你有任何ide如何杀死那些睡觉(空闲)的PHP进程?有什么我做错了吗?

1 个解决方案

#1


3  

edem, I think you shouln't kill em. As fastcgi idea not to spawn new processes. See http://en.wikipedia.org/wiki/FastCGI#Implementation_details

edem,我想你不应该杀死他们。由于fastcgi想法不产生新的进程。请参见http://en.wikipedia.org/wiki/FastCGI#Implementation_details

Instead of creating a new process for each request, FastCGI uses persistent processes to handle a series of requests. These processes are owned by the FastCGI server, not the web server.

FastCGI不是为每个请求创建新进程,而是使用持久进程来处理一系列请求。这些进程归FastCGI服务器所有,而不是Web服务器。

As a workaround you can try to play with your webserver fcgi settings to for example reduce "sleepin" number. Also I think your admin tells you about some peak usage, but we don't see it here, as you top your memory in possible calm time.

作为一种解决方法,您可以尝试使用您的网络服务器fcgi设置,例如减少“sleepin”号码。此外,我认为你的管理员会告诉你一些高峰用法,但是我们在这里看不到它,因为你可以在平静的时间里记住你的记忆。

#1


3  

edem, I think you shouln't kill em. As fastcgi idea not to spawn new processes. See http://en.wikipedia.org/wiki/FastCGI#Implementation_details

edem,我想你不应该杀死他们。由于fastcgi想法不产生新的进程。请参见http://en.wikipedia.org/wiki/FastCGI#Implementation_details

Instead of creating a new process for each request, FastCGI uses persistent processes to handle a series of requests. These processes are owned by the FastCGI server, not the web server.

FastCGI不是为每个请求创建新进程,而是使用持久进程来处理一系列请求。这些进程归FastCGI服务器所有,而不是Web服务器。

As a workaround you can try to play with your webserver fcgi settings to for example reduce "sleepin" number. Also I think your admin tells you about some peak usage, but we don't see it here, as you top your memory in possible calm time.

作为一种解决方法,您可以尝试使用您的网络服务器fcgi设置,例如减少“sleepin”号码。此外,我认为你的管理员会告诉你一些高峰用法,但是我们在这里看不到它,因为你可以在平静的时间里记住你的记忆。