1

PHP-FPM process getting crashed in every few days due to reached pm.max_children, I have to manually start it to make the site up.

Server Configuration:

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

PHP-FPM Configuration:

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

Check the PHP-FPM log and found the following error.

[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

I can someone please suggest the best-optimized configuration for the PHP-FPM, Which can help to avoid the crashed.

What does this below line means:

[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
  • 1
    How busy is your server? Do you really have 280 simultaneous requests to your server? That would probably represent thousands of users using your website at one time, and would use a LOT of CPU - two cores would probably be 100% used. I wonder if you have a PHP bug or some weird configuration that's not releasing PHP workers. I also suggest you consider page caching for anonymous users, that can increase performance significantly and reduce PHP load. – Tim Aug 3 '17 at 20:12
  • 1
    Going from 31 active workers to 280 in a 30 second period sounds like a DDoS or something to me. That's one hell of a traffic spike. – ceejayoz Aug 3 '17 at 20:16
  • It's a app server, User installs the app and it start sending ajax request from client end in every refresh.. that's why it's busy... but this process does not take much time to execute just one select query and returns the data..right now i am using APC.. any suggestion? – Irk Aug 4 '17 at 10:45
0

Here's one suggestion for calculating the right number:

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

the following command will help us to determine the memory used by each (PHP-FPM) child process:

ps -ylC php-fpm --sort:rss

Then you take your server's available RAM and calculate:

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

Also see:

php5-fpm: server reached pm.max_children

0

The first off all you should find out how many fpm children you realy need. Enable slow log in your pool config or use external services like NewRelic to find slow and weak spots in your code. May be you have bottleneck in MySQL connection or PHP-curl. You got "seems busy" because they are busy with waiting an answer from DataBase or something else. Increasing pm.max_children without reason is a bad practice.

  • Thanks Alexander.. It make sense. I'll check for those cases first. – Irk Aug 8 '17 at 4:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.