PHP-FPM using 100% CPU on a server that has 16 threads
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/
Related videos on Youtube
viniciussvl
Updated on September 18, 2022Comments
-
viniciussvl over 1 year
I have a server that has 32 GB of RAM and 16 threads. This server has an API in PHP that receives many requests from other external APIs, I made a configuration in PHP-FPM to support all these requests without slowing down the site, this worked well for 1 year, now the requests have practically doubled and this is leaving website pages are slow, taking 5-6 seconds to load, which is not normal. Maybe I have to redo a configuration in PHP-FPM to support this new demand for requests, what would you do in this situation?
My server has 32 GB of RAM, but uses only 2.5 GB, is that okay? Is it possible to maintain a balance between RAM and CPU to improve CPU performance or am I talking nonsense?
pm.max_children = 32 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 pm.max_requests = 1000
There are 32 children of PHP-FPM running the processes.
-
viniciussvl about 3 yearsIn this configuration, the RAM will keep increasing until reaching the limit of 32 GB ram?
-
viniciussvl about 3 yearsI 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 8/32 GB.
-
Bogdan Stoica about 3 yearsI'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!