How to calculate pm.max_children setting?
Check how much memory the average process is using, to be able to calculate how many processes we can execute with the RAM available in our server.
$ ps -ef | grep '[f]'pm //Results on this machine : root 4073 1 0 Sep19 ? 00:02:02 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf) www-data 24905 4073 1 18:14 ? 00:00:29 php-fpm: pool www www-data 25056 4073 1 18:30 ? 00:00:11 php-fpm: pool www www-data 25125 4073 1 18:32 ? 00:00:09 php-fpm: pool www
Check the memory that is required for these processes:
$ ps -C php-fpm7.4 -o rss= //Results on this machine : 21080 92892 91272 90816
Generally, the first line of this list shows the master process, which in this case is running PHP, and the following results show the resources that each child process uses. These numbers are in kilobytes, so in this example, I would ignore the first process and round to establish an average of 100 MB of physical memory per child process.
[RAM disponible total] - [RAM reservada] - [10% de búfer] = [RAM disponible para PHP] [RAM disponible para PHP] / [Tamaño medio del proceso] = [max_children]
pm.max_children = [max_children] pm.start_servers = [25% de max_children] pm.min_spare_servers = [25% de max_children] pm.max_spare_servers = [75% de max_children]
Calculator
https://spot13.com/pmcalculator/