Sorry, I am new and deleted my question thinking I had posted some info I should not have. I am posting the edited question once again:

In our website, php5-fpm takes care of the PHP calls made by the browser. We have received a lot of outages/504s lately. Now, I checked the php5-fpm logs to correlate with the timestamps of 504 in our access logs and this is what I got in the php5-fpm logs:

WARNING: [pool www] server reached pm.max_children setting (5), consider raising it

Please observe that the php5-fpm was not able to handle the connections since it has a current limit of pm.max_children setting set only to 5 (please see below) and is way too less based on our workload:

unknown@xxxx:~# cat /etc/php5/fpm/pool.d/www.conf | grep "pm.max_children =" pm.max_children = 5

My question is, how do I calculate the new value? I have 4 GB of RAM and the DB is running on a diff server.

2 Answers 2


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
  • Now, for your specific case:
  • 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 of 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.
  • 1
    Thanks a lot! I do not see the error messages after changing the value.
    – Dadda
    Jan 2, 2019 at 21:14

To supplement st_rt_dl_8's answer, if php-fpm is running inside a container which is missing the ps command but all the processes are being run as a specific user, say www-data, then the following can be used to get memory size (assuming awk is available):

for i in `ls -l /proc/ | awk '/www-data/{print $9}'`; \
do grep VmRSS /proc/$i/status; \
done | awk '{n = $2 / 1024; print n, "Mb"}'
57.2773 Mb
57.8555 Mb
55.5742 Mb
32.5898 Mb
32.7422 Mb

And to calculate the average add the following pipe ... | awk 'BEGIN {n=0; sum=0} {n = n + 1; sum = sum + $1} END {print sum / n}'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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