1.PHP-FPM two modes of instruction
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.
Let's talk about some of the parameters that are involved here:
PM, Pm.max_children, Pm.start_servers, Pm.min_spare_servers, and Pm.max_spare_servers.
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.
2. Parameter description
The meanings of the 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, 1024M VPS, recommended pm.max_spare_servers set to 50. As for Pm.min_spare_servers, it is recommended to set the load on the server and compare the appropriate values between 20~30.
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.
3. View memory and Configuration
# free-m Total used free shared buffers cachedmem:15949 5201 10747 0 303 1626-/+ buffers/cache:3271 12677swap:2047 0 2047
Configuration of 16G Memory:
pm=dynamicpm.max_children=512pm.start_servers=256pm.min_spare_servers=128pm.max_spare_servers=512
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. The number of static child processes is fixed (pm.max_children). The ondemand process is generated when there is a demand (when requested, the opposite of dynamic ,pm.start_servers starts when the service starts. The number of dynamic 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 intpm set to static indicates the number of child processes created,pm set to dynamic Represents the maximum number of child processes that can be created. Must be set. This option sets a limit on the number of requests that can be served at the same time. Similar to Apache mpm_prefork MaxClients settings and php_ in common php fastcgi fcgi_children environment variables. Pm.start_serversin sets the number of child processes created at startup. Used only when pm is set to dynamic . The default value is: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 pm is set to dynamic . Must be set. Pm.max_spare_servers int sets the maximum number of idle service processes. Used only when pm is set to dynamic . Must be set. Pm.max_requests int sets the number of requests for services before each child process is reborn. is useful for third-party modules that may have a memory leak. If set to ' 0 ' then a directrequested, equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value: 0.
This article is from the "OPS rookie" blog, please be sure to keep this source http://ckl893.blog.51cto.com/8827818/1765703
PHP-FPM Process Management Differences