My server runs 10 websites, very low traffic. Config:
- Ubuntu 20.04.5 LTS
- Nginx 1.18.0 (Ubuntu)
- PHP 7.4.3
In nginx.conf this is added:
upstream local_php {
server unix:/run/php/php7.4-fpm.sock;
}
In sites-enabled the config files have locations including:
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass local_php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
My /etc/php/7.4/fpm/pool.d/www.conf has:
pm = ondemand
pm.max_children = 15
pm.max_requests = 10
Now what happens is that my sites are running fine, but the php log file shows that the number of active children is steadily increasing. After a day or so, it reaches 15 and then PHP stops working. Looking at the process listing, there are children of all 'ages' that just seem to live on without purpose. There are no warnings in the PHP log file, only this one, when max_children
is reached:
WARNING: pid 75057, fpm_pctl_on_socket_accept(), line 518: [pool www] server reached max_children setting (15), consider raising it
I've been trying to tweak PHP settings. With pm = dynamic
, max_children are reached much faster. max_requests
was higher at first, but lowering it made no significant difference. I have sufficient resources for increasing max_children
a bit, but that only postponing the problem, not solving it.
Note that my server has no load issues. The memory usage never exceeds 35% and CPU is steady at 5%.
I must be doing something wrong, because I suppose the children should be killed at some point, shouldn't they? The PHP log says that children are being killed, but this is always decreasing the count of spare children, neven of active children:
DEBUG: pid 232350, fpm_pctl_perform_idle_server_maintenance(), line 365: [pool www] currently 8 active children, 2 spare children
DEBUG: pid 232350, fpm_got_signal(), line 82: received SIGCHLD
DEBUG: pid 232350, fpm_event_loop(), line 435: event module triggered 1 events
DEBUG: pid 232350, fpm_children_bury(), line 261: [pool www] child 289966 has been killed by the process management after 12.069386 seconds from start
DEBUG: pid 232350, fpm_pctl_perform_idle_server_maintenance(), line 365: [pool www] currently 8 active children, 1 spare children
DEBUG: pid 232350, fpm_got_signal(), line 82: received SIGCHLD
DEBUG: pid 232350, fpm_event_loop(), line 435: event module triggered 1 events
DEBUG: pid 232350, fpm_children_bury(), line 261: [pool www] child 289969 has been killed by the process management after 12.665847 seconds from start
DEBUG: pid 232350, fpm_pctl_perform_idle_server_maintenance(), line 365: [pool www] currently 8 active children, 0 spare children
Typical process list with children amounting up to 15:
1390 vps@vps9029:/etc/php/7.4/fpm/pool.d $ ps -elf|grep php
4 S root 15528 15439 0 80 0 - 2397 - Dec20 pts/1 00:00:00 sudo tail -f php7.4-fpm.log
4 S root 15537 15528 0 80 0 - 1378 - Dec20 pts/1 00:00:12 tail -f php7.4-fpm.log
4 S root 75057 1 0 80 0 - 59077 - Dec21 ? 00:00:26 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
5 S www-data 94817 75057 0 80 0 - 84357 - Dec21 ? 00:00:00 php-fpm: pool www
5 S www-data 104885 75057 0 80 0 - 84302 - Dec21 ? 00:00:00 php-fpm: pool www
5 S www-data 125566 75057 0 80 0 - 66282 - Dec21 ? 00:00:01 php-fpm: pool www
5 S www-data 143879 75057 0 80 0 - 65617 - 02:47 ? 00:00:00 php-fpm: pool www
5 S www-data 149198 75057 0 80 0 - 84441 - 03:56 ? 00:00:00 php-fpm: pool www
5 S www-data 149632 75057 0 80 0 - 84582 - 04:02 ? 00:00:08 php-fpm: pool www
5 S www-data 152959 75057 0 80 0 - 84515 - 04:43 ? 00:00:01 php-fpm: pool www
5 S www-data 178687 75057 0 80 0 - 65673 - 09:53 ? 00:00:00 php-fpm: pool www
5 S www-data 182987 75057 0 80 0 - 84178 - 10:46 ? 00:00:00 php-fpm: pool www
5 S www-data 187712 75057 0 80 0 - 84178 - 11:44 ? 00:00:00 php-fpm: pool www
5 S www-data 187713 75057 0 80 0 - 84178 - 11:44 ? 00:00:00 php-fpm: pool www
5 S www-data 197529 75057 0 80 0 - 84386 - 13:59 ? 00:00:00 php-fpm: pool www
5 S www-data 210404 75057 0 80 0 - 65569 - 16:48 ? 00:00:00 php-fpm: pool www
5 S www-data 213858 75057 0 80 0 - 65633 - 17:29 ? 00:00:00 php-fpm: pool www
5 S www-data 214975 75057 0 80 0 - 85465 - 17:44 ? 00:00:00 php-fpm: pool www