PHP5-FPM pm.max_children affect RAM or CPU+RAM

performanceperformance-tuningphp-fpm

Recently inherited a Nginx+PHP5-FPM server, and I'm learning and trying to optimize PHP5-FPM settings.

Server info:

4 CPUs (8 threads)
7.5 GiB RAM

PHP5-FPM info:

pm.max_children = 5
pm.min_spare_servers = 1
pm.max_spare_servers = 3
;pm.process_idle_time = 10s;
;pm.max_requests = 500

(I'm going to uncomment the max_requests line, since that appears to be a recommended thing to do.)

When the website is under load, each PHP5-FPM process has very high CPU usage but I have yet to see a process go over 1% RAM usage.

Everywhere that I look (eg here and here) only talks about increases of pm.max_children being limited by RAM, and doesn't mention CPU usage.

In my case, would increasing pm.max_children increase or decrease my website's performance, based on the fact that it is more CPU bound than RAM bound? In other words, as pm.max_children increases is RAM the only consideration or is CPU also affected?

[Edit] Not a duplicate: The question basically boils down to the final sentence, which is not asking for advice about capacity planning; it is asking if CPU usage is a consideration in the pm.max_children setting or if it is solely RAM that is increased.

Best Answer

It depends on what your PHP scripts are doing. But 5 is really low number for PHP processes. Usually the PHP process will open connection to MySQL (takes time), wait for MySQL to process the query (takes time), so it won't be using CPU all the time and with only 5 processes the CPU can be idle some moments, but there will be no other PHP process to use it. So you can safely increase the limit to at least 20-30 (or more, depending on how manuy req/s you receive).

Regarding the question on CPU usage. Having more active PHP processes at the same time won't increase the CPU usage. All the CPU power you have available will be divided between running processes.

Related Topic