PHP-FPM Configuration – How to Know Number of Children and Servers

php-fpm

I realised a big problem today, too much traffic made my website totally down but i have a big server to host it. Here's what i got :

[20-May-2019 14:23:02] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 4 idle, and 22 total children
[20-May-2019 14:23:03] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 3 idle, and 30 total children
[20-May-2019 14:23:04] 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 42 total children
[20-May-2019 14:23:05] 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 57 total children
[20-May-2019 14:23: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 72 total children
[20-May-2019 14:23: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 87 total children
[20-May-2019 14:23: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 102 total children
[20-May-2019 14:23: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 117 total children
[20-May-2019 14:23: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 9 idle, and 132 total children

But i thought i have configured enough children on my fpm with this config :

  • pm.max_children = 100
  • pm.start_servers = 15
  • pm.min_spare_servers = 15
  • pm.max_spare_servers = 25

But i got this error. Do you know how many i can setup for accept more traffic ? I have 32gb of RAM and 8 cores

Best Answer

That log file implies 110 processes started in 8 seconds. Note that it started multiple batches of 32 in quick succession. pm.min_spare_servers = 15 will not be able to absorb such a connection increase, response time will be terrible.

Keep enough idle processes to absorb your biggest connection spikes, and the maximums above that. If you have sufficient memory and CPU, of course. Try something like this:

pm.max_children = 500
pm.min_spare_servers = 100
pm.max_spare_servers = 200

Keep tuning this as a part of your capacity planning process. For example, you may have the resources to increase even more. Or maybe you reach a point where you do not need more php-fpm, and the resources would be better spent on other workloads on the host.

Also on Server Fault: WARNING: pool www seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers)

Related Topic