php-fpm separates php processes into subprocesses, each of which is responsible for processing one php request at a time. Using a maximum process value php-fpm children is possible to know the maximum value of memory that can be consumed based on the value of memory_limit.
It means that,
pm.max_children * memory_limit ~= Quantity maxim memory that can be used by a php-fpm pool.
In your case, let’s assume that the value of memory_limit is 128M, then we will have:
25 * 128M ~= 3200M
The maximum amount of memory your php-fpm should use is approximately 3.2Gb, being a machine shared with the Operating System and NGINX, the value would already be close to the limit.
If your php scripts consume less than 128M it is possible to increase the request capacity that this server will receive.
To find out how much memory your request is spending you can create a log:
$initialMem = memory_get_usage();
// ... Tudo aqui
$finalMem = memory_get_peak_usage();
error_log('Defina um label ou coloque o nome do arquivo usando __FILE__ '.($finalMem - $initialMem)/1024 . " Kbytes"); //Armazena no log o uso de memória
Remember that php scripts can modify this value using the init_set function, if available.
ini_set('memory_limit', '2048M');
You can raise the value of pm.max_requests
for a child process of php-fpm to receive more requests before it is restarted and reduce the pm.process_idle_timeout
to 5 seconds (5s) so that the process does not stay so long idle increasing the ability to obtain requests a little.
In a way, this is an estimate, it is necessary to adjust the parameters according to your demand and the characteristic of your application.
I know it’s been a while, but I would like to comment on something important, often you can even make a great setup, but the problem is in the web-application and not in the server itself. Many applications like Wordpress have a high consumption. However CMS like wordpress has plugins for caching, and even if it is not a CMS, if it is an application of yours it is likely to use a framework, so you can look for a PHP solution for caching both front and back :)
– Guilherme Nascimento