How should I set the number of PHP-FPM child processes?

Source: Internet
Author: User
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.

  • The advantage is that you do not need to dynamically determine load conditions to improve performance;

  • The disadvantage is that it occupies more system memory resources.

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.

  • Firstmax_childnrenSet it to a relatively large value.
  • Observephp-fpmOfstatusInmax active processesWhat is
  • Thenmax_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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.