Comparison of static and dynamic execution modes of PHP-FPM

Source: Internet
Author: User
More please poke: http://www.webyang.net/Html/web/article_242.html

The previous time configuration php-fpm, inadvertently found that he still has two ways of execution. Like Apache, his number of processes can be divided into dynamic and static according to the settings.


And PHP-FPM also exist in two ways, one is directly open the specified number of PHP-FPM process, no longer increase or decrease, the other is to start a certain number of php-fpm process, when the request is large, dynamically increase the number of PHP-FPM process to the upper limit, The number of idle processes is automatically freed to a lower limit when idle.
These two different execution modes can be adjusted according to the actual needs of the server.
Here are some of the parameters that relate to this, they are pm, Pm.max_children, Pm.start_servers, Pm.min_spare_servers and Pm.max_spare_servers respectively.
PM means that there are two values that can be selected, either static or dynamic, in that way. In older versions, dynamic is called Apache-like. This should pay attention to the instructions given in the configuration file.
The meanings of the following 4 parameters are:
Pm.max_children: The number of PHP-FPM processes that are open in static mode.
Pm.start_servers: The number of start PHP-FPM processes under dynamic mode.
Pm.min_spare_servers: The minimum number of PHP-FPM processes under dynamic mode.
Pm.max_spare_servers: The maximum number of PHP-FPM processes under dynamic mode.
If the DM is set to static, then only pm.max_children this parameter takes effect. The system turns on the set number of PHP-FPM processes.
If the DM is set to dynamic, then the Pm.max_children parameter is invalidated and the next 3 parameters take effect. The system starts the Pm.start_servers PHP-FPM process at the beginning of the PHP-FPM run and then dynamically pm.min_spare_servers and Pm.max_spare_ according to the system's requirements Adjusts the number of PHP-FPM processes between servers.
So, for our server, which method of execution is better? In fact, like Apache, we run a PHP program after the completion of execution, more or less there is a memory leak problem. This is why the beginning of a PHP-FPM process only consumes about 3M of memory, running for a period of time will rise to 20-30m reason. Therefore, the dynamic mode because it will end the redundant process, can be reclaimed to release some memory, so it is recommended to use on the server or VPS with less memory. The specific maximum number is based on the memory/20m. For example, 512M VPS, recommended pm.max_spare_servers set to 20. As for Pm.min_spare_servers, it is recommended to set the load on the server and compare the appropriate values between 5~10.
Then, for servers that are larger in memory, it is more efficient to set to static. Because the frequent switch PHP-FPM process will also sometimes lag, so the memory is large enough to open the static effect will be better. The quantity can also be obtained according to the memory/30m. For example, 2GB memory server, can be set to 50;4GB memory can be set to 100 and so on.
This site is built on the 512M VPS, so I set the parameters as follows:
Pm=dynamic
Pm.max_children=20
Pm.start_servers=5
Pm.min_spare_servers=5
Pm.max_spare_servers=20
This allows for maximum memory savings and increased execution efficiency.
The parameter description is attached:
PM string
Sets how the Process manager manages child processes. Available values: Static,ondemand,dynamic. Must be set.
Static-The number of child processes is fixed (pm.max_children).
OnDemand-The process is generated when there is a demand (as opposed to dynamic when requested, Pm.start_servers starts when the service starts.)
Dynamic-The number of child processes is dynamically set based on the following configuration: Pm.max_children,pm.start_servers,pm.min_spare_servers,pm.max_spare_servers.
Pm.max_children int
The number of child processes created when PM is set to static indicates the maximum number of child processes that can be created when the PM is set to dynamic. Must be set.
This option sets a limit on the number of requests that can be served at the same time. Similar to the maxclients settings in Apache mpm_prefork and the Php_fcgi_children environment variables in normal PHP fastcgi.
Pm.start_serversin
Sets the number of child processes created at startup. Used only when the PM is set to dynamic. Default value: Min_spare_servers + (Max_spare_servers-min_spare_servers)/2.
pm.min_spare_servers int
Sets the minimum number of idle service processes. Used only when the PM is set to dynamic. Must be set.
pm.max_spare_servers int
Sets the maximum number of idle service processes. Used only when the PM is set to dynamic. Must be set.
pm.max_requests int
Sets the number of requests for the service before each child process is reborn. is useful for third-party modules that may have a memory leak. If set to ' 0 ', the request is always accepted, equivalent to the php_fcgi_max_requests environment variable. Default value: 0.

The above describes the static and dynamic execution of php-fpm comparison, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.