http linux | unix ssh

[Resolved!] server reached pm.max_children setting (AnyNumber)

How to fix “server reached pm.max_children setting (AnyNumber)”

The following fix was tested on the following specs of the stack however, the fix will work on other versions as well:

  • OS – Linux 3.2.0-4-amd64 x86_64
  • Memory/RAM – 4GB
  • MySQL DB is running on a different server

  • WebServer – nginx/1.2.1
  • PHP – PHP 5.4.44-0+deb7u1 (cli)
  • PHP5-FPM – PHP-FPM is PHP’s FastCGI implementation and runs as a standalone FastCGI server. So, in simple words, nginx will pass any PHP request for dynamic content to the socket on which the FastCGI server is listening governed by fastcgi_pass  directive in nginx configuration file.

Context of the error message:

  • Your website is frequently going down with your web-server sending HTTP 504/502 to the end user.
  • When you check the error logs of your web-server corresponding to the timestamps of 504/502 messages in the access logs you get nothing significant.
  • Then you check the php5-fpm logs `zgrep “pm.max_children” /var/log/php5-fpm` and you see this “server reached pm.max_children setting (AnyNumber)” error message.
  • Sample error message in php5-fpm logs: `WARNING: [pool www] server reached pm.max_children setting (5), consider raising it`

Cause of this error message:

NGINX and was not able to entertain further php calls as php5-fpm had reached the max children limit defined in the stock configuration of php5-fpm process management config file (/etc/php5/fpm/pool.d/www.conf)

Resolution:

To re-iterate, the cause for this error message is that the pm.max_children value defined in the stock configuration of php5-fpm process management config file (/etc/php5/fpm/pool.d/www.conf) is quite low. From the sample error message above, it’s 5.

To find out the correct value, we need to find the average memory being used by one php-fpm process.

Active php-fpm processes memory consumption: root@example:~# ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | grep php-fpm

  • 111.50 Mb php-fpm: pool www
  • 55.60 Mb php-fpm: pool www
  • 52.25 Mb php-fpm: pool www
  • 12.45 Mb php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
  • 0.31 Mb grep php-fpm
  • Average memory consumption per process: (111.50+55.60+52.25)/3 = 73.12 Mb
  • Total available memory = 4000 Mb and since DB is running on a separate server, it would be safe to consume 3000 Mb of memory.
  • So, the new numbers of pm.max_children based on the above calculation = 3000/74 = 40.54 ~ 40
  • Upon setting the correct value, you should not see pm.max_children error/warning in your php-fpm logs.

I have explained the same in this ProWebmasters StackOverflow community answer , as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

18 − 13 =