服务器达到pm.max_children设置(280),考虑提高它

PHP-FPM进程因为达到pm.max_children而每隔几天就会崩溃 ,我必须手动启动它才能build立站点。

服务器configuration:

Total Memory: 7986M CPU: 2 Core 1 PHP Process Taking: 22M 

PHP-FPMconfiguration:

 pm = dynamic pm.max_children = 280 pm.start_servers = 15 pm.min_spare_servers = 15 pm.max_spare_servers = 35 pm.max_requests = 1000 

检查PHP-FPM日志,发现以下错误。

 [02-Aug-2017 23:23:54] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 10 idle, and 41 total children [02-Aug-2017 23:24:04] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 55 total children [02-Aug-2017 23:24:05] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 63 total children [02-Aug-2017 23:24:06] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 78 total children [02-Aug-2017 23:24:07] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 93 total children [02-Aug-2017 23:24:08] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 108 total children [02-Aug-2017 23:24:09] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 123 total children [02-Aug-2017 23:24:10] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 138 total children [02-Aug-2017 23:24:11] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 153 total children [02-Aug-2017 23:24:12] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 168 total children [02-Aug-2017 23:24:13] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 183 total children [02-Aug-2017 23:24:14] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 198 total children [02-Aug-2017 23:24:15] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 213 total children [02-Aug-2017 23:24:16] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 228 total children [02-Aug-2017 23:24:17] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 243 total children [02-Aug-2017 23:24:18] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 258 total children [02-Aug-2017 23:24:19] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 273 total children [02-Aug-2017 23:24:20] WARNING: [pool www] server reached pm.max_children setting (280), consider raising it 

我可以有人请build议PHP-FPM的最佳优化configuration,这可以帮助避免坠毁。

下面这条线是什么意思:

 [02-Aug-2017 23:23:54] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 10 idle, and 41 total children 

这里有一个计算正确数字的build议:

https://myshell.co.uk/blog/2012/07/adjusting-child-processes-for-php-fpm-nginx/

以下命令将帮助我们确定每个(PHP-FPM)subprocess使用的内存:

 ps -ylC php-fpm --sort:rss 

然后你把你的服务器的可用RAM和计算:

 pm.max_children = Total RAM dedicated to the web server / Max child process size 

另请参阅:

php5-fpm:服务器达到pm.max_children

首先,你应该知道你真正需要多lessfpm儿童。 启用缓慢login您的池configuration或使用外部服务,如NewRelic在您的代码中find缓慢和弱点。 可能是你有MySQL连接或PHPcurl的瓶颈。 你看起来很忙,因为他们忙于等待DataBase或其他的答案。 无理地增加pm.max_child是一个不好的做法。