Today, I will tell you about my web server suddenly went down. Can not be accessed.
The web server using Centos 7, Apache and PHP-FPM as php-handler. And how to fix Server reached pm.max_children.
Check Log to Identify server reached pm.max_children
When web the server goes down, I immediately check the log. Apache Logs and PHP-FPM Logs.
In Apache logs, it’s normal. Nothing strange. But when in the PHP-FPM log there is a line that shows like this:
[18-May-2022 08:19:34] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 2 idle, and 26 total children [18-May-2022 08:48:35] WARNING: [pool www] server reached pm.max_children setting (50), consider raising it
The message indicates that the pm.max_children configuration has reached its limit, this is due to several possibilities including:
- There are many visitors accessing at the same time.
- Issue server resources, resulting in slow execution of PHP scripts.
- The max_children setting is too low.
Configuring pm.max_children that is not in place can result in the website being inaccessible with an error message 502 Bad Gateway or 503 Service Temporarily Unavailable.
So if you encounter the above warning message, all you need to do is adjust the pm.max_children value in the PHP-fpm configuration.
Tips for Determining the Value of pm.max_children
Example:
- Total RAM 2 GB, RAM allocation for web server 1.5 GB (1500MB)
- The average php-fpm RAM usage is 32 MB.
How to check The average php-fpm RAM usage? Use the following command:
[~]# ps -C php-fpm -o rss=
17076
31680
31648
31688
31660
29588
31720
Base the result showing RAM usage in 32mb. So the correct value of pm.max_children is = 1500MB/32MB Approx: 48.
fill the value pm.max_children in /etc/php-fpm.d/www.conf with value 48.
Save and then restart services php-fpm.
systemctl restart php-fpm
Important Notes :
To determine the correct value of pm.max_children, the calculation above is if the server has dedicated memory for the web server. In other words, if the server used is shared hosting or the PHP code installed is complex and requires high resources, the calculations above may be different and need to be adjusted again.
May be it’s helpful, please feel free to leave a comment if you have any questions and I’ll appreciate it.
Credit Source:
- https://chrismoore.ca/2018/10/finding-the-correct-pm-max-children-settings-for-php-fpm/
- https://spot13.com/pmcalculator/
- https://gist.github.com/holmberd/44fa5c2555139a1a46e01434d3aaa512