If I'm reading correctly you only have 8GiB of memory. If your Magento instance gets a decent amount of traffic and/or you're not serving your static files (css and js) from a CDN, Magento 2 will eat up your memory pretty quickly.
If you just want to ensure you're only spawning php-fpm workers as needed you can edit your php-fpm pool configuration file www.conf
. The location of this file depends on the Linux distro you're using, for instance on Ubuntu Server this file is located at /etc/php/<php version>/pool.d/www.conf
. Once you find the file open it and edit the following configuration options.
NOTE: These options are already present in the file so you'll need to find them and update the value, don't just paste this into the file
pm=dynamic
pm.max_children=20
pm.start_servers=10
pm.min_spare_servers=5
pm.max_spare_servers=15
Note the values for pm.max_children
, pm.start_servers
, pm.min_spare_servers
, and pm.max_spare_servers
will more than likely need to be tweaks to your needs, and the values I provided are on the low side.
Now you just need to restart your php-fpm process for the changes to take effect.
When pm
is set to dynamic
the php-fpm master process will spawn php-fpm workers as needed based on the values set above. When pm
is set to static
the php-fpm master process will always spawn the the maximum number of workers allowed based on the value of pm.max_children