This article mainly introduces how to set the number of PHP-FPM sub-processes ?, If you are interested in the PHP Tutorial, refer. First, we pay attention to the PHP-FPM running mode:
Static: indicates that when 'php-fpm' is run, 'fork' output 'PM directly. max_chinance' sub-process, dynamic: indicates that during the runtime, 'fork' generates 'start _ servers' processes, which are dynamically adjusted according to the load, A maximum of 'max _ children 'processes are allowed.
Recommendedstatic.
PHP-FPMThe number of sub-processes, the more the better?
Of course not,pm.max_chindrenWhen there are too many processes, the overhead of process management and the overhead of context switching are increased.
What's more important is that it can be executed concurrently.php-fpmThe process will not exceedcpuNumber.
How to set it depends on your code
-
If the code isCPUComputing-intensive,pm.max_chindrenCannot exceedCPUNumber of kernels.
-
If notpm.max_chindrenThe value is greaterCPUIs wise.
Foreign technical experts give this formula:
InN + 20%AndM / m.
N indicates the number of CPU cores.
M is the amount of memory that PHP can use.
M indicates the average memory usage of each PHP process.
ApplicabledynamicMethod.
staticMethod:M / (m * 1.2)
Of course, there is also an insurance method to configuremax_children. ApplicablestaticMethod.
- First
max_childnrenSet it to a relatively large value.
- Observe
php-fpmOfstatusInmax active processesWhat is
- Then
max_childrenThe configuration is larger than it.
pm.max_requests: Indicates the number of requests processed by each sub-process and the number of requests restarted.
This parameter can be set at will theoretically, but it is better to set a reasonable number to prevent the risk of memory leakage.
The above introduces how to set the number of PHP-FPM sub-process ?, Including some content, hope to be helpful to friends who are interested in PHP tutorials.