It is a question whether PHP-FPM consumes memory or CPU,.

when optimizing PHP-FPM, there are usually two ways of thinking:

  • setting pm.max_children, according to the number of CPU cores, such as * 2 + 2 cores, will pull the CPU very high, more than 70%, under the same pressure, but there is almost no fluctuation in memory.
  • set pm.max_children, such as 30M/ * 100 = 3GB memory usage according to the number of memory. In this case, the memory will be pulled very high and fluctuate regularly with the recovery cycle, but the CPU does not fluctuate much, basically 10-40%.

from the test results of ab-c500-n 100000, the configuration is a little bit faster according to the number of CPU cores, which is not particularly obvious. If you use the amount of memory to configure, I feel that CPU computing resources are wasted again, and I am unwilling to do so.

do you have any suggestions?

Nov.28,2021

max_children is definitely too small to set to cpu * 2 + 2. With your 500 requests per second, assuming cpu = 4, a maximum of 10 fpm processes will be created. If you have one 100ms request, you will be able to receive almost (1000 amp 100) * 10 = 100 requests per second. The extra will have to wait for the master creation process, and naturally cpu will go up.

it is recommended to set pm.start_servers, according to the average number of visits per day. The max_children cannot exceed 2/3 of the total memory. If it is a server dedicated to web access, pm=static is recommended.

Menu