PHP-FPM using 100% CPU on a server that has 8GB RAM and 4 Core
On my server, there are 4 core CPUs and 8GB of RAM. This server has a PHP API that receives a lot of requests from other external APIs. I set up PHP-FPM to handle all of these requests without causing the site to load slowly. However, one website uses an excessive number of PHP-FPM connections while setting PHP8.4, however this is not the case with PHP8.3.
Is it feasible to keep RAM and CPU in balance to enhance CPU performance, or what could be the likely
pm.max_children = 250
pm.max_requests = 1000
1 Answers
I would use php-fpm settings with pm = static. From my experience high traffic websites work better with pm static rather than dynamic/ondemand.
You can get an ideea about the memory used by a php-fpm process using the command bellow:
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
I would modify the php-fpm config with something like this:pm.max_children = 25
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 1000
Restart php-fpm afterwards!
As a side note, here's a very interesting article that can explain a lot and guide you to find the best configuration: https://thisinterestsme.com/php-fpm-settings/In this configuration, the RAM will keep increasing until reaching the limit of 8 GB ram? - 1I read the article and calculated the settings based on the ram used by each process (45MB). I changed it to static and put 600 in max_children, the site got faster. RAM is now using 2/8 GB
- I'm glad it works! You would need to have really huge traffic to jum up the ram from 8 to 32G. Probably 600 is a little bit too much with your actual configuration but you can play with the settings according to your needs!
Please login or Register to submit your answer