PHP-FPM pm.max spare servers

From CS Wiki
Revision as of 21:45, 29 November 2024 by Fortify (talk | contribs) (Created page with "'''pm.max_spare_servers''' is a configuration directive in PHP-FPM (FastCGI Process Manager) that specifies the maximum number of idle (spare) worker processes to maintain in the pool. It is used when the process manager (pm) is set to '''dynamic'''. This directive ensures that server resources are not wasted by limiting the number of idle worker processes. ==Overview== In dynamic process management mode, PHP-FPM adjusts the number of worker processes based on the server...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

pm.max_spare_servers is a configuration directive in PHP-FPM (FastCGI Process Manager) that specifies the maximum number of idle (spare) worker processes to maintain in the pool. It is used when the process manager (pm) is set to dynamic. This directive ensures that server resources are not wasted by limiting the number of idle worker processes.

Overview[edit | edit source]

In dynamic process management mode, PHP-FPM adjusts the number of worker processes based on the server's workload. The `pm.max_spare_servers` directive sets an upper limit on the number of idle processes to prevent excessive resource usage while still keeping spare workers ready to handle incoming requests.

Key characteristics:

  • Controls the maximum number of idle worker processes.
  • Only applicable in the dynamic process management mode.
  • Helps optimize resource usage while ensuring availability.

Default Value[edit | edit source]

The default value of `pm.max_spare_servers` is typically set to `10`, but it can vary depending on the PHP-FPM version or distribution.

Configuration Example[edit | edit source]

Here is an example of configuring `pm.max_spare_servers` in the PHP-FPM pool configuration file (e.g., `www.conf`):

; Set the maximum number of spare (idle) servers
pm = dynamic
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.start_servers = 7
pm.max_children = 50

Explanation[edit | edit source]

  • `pm = dynamic`: Enables dynamic process management mode.
  • `pm.max_spare_servers = 15`: Limits the maximum number of idle worker processes to 15.
  • `pm.min_spare_servers = 5`: Ensures a minimum of 5 idle worker processes are maintained.

Applicability[edit | edit source]

The `pm.max_spare_servers` directive is useful in scenarios where:

  • Traffic fluctuates significantly, and a balance is needed between resource usage and request handling capacity.
  • The server must avoid creating too many idle processes that waste memory and CPU.

Advantages[edit | edit source]

  • Prevents resource over-allocation by capping the number of idle worker processes.
  • Helps maintain optimal performance during periods of low traffic.
  • Works seamlessly with dynamic process management to adjust to varying loads.

Limitations[edit | edit source]

  • Setting the value too low can lead to performance bottlenecks during traffic spikes.
  • Does not apply to other process management modes such as static or ondemand`.

Related Directives[edit | edit source]

  • pm.min_spare_servers: Sets the minimum number of idle worker processes.
  • pm.start_servers: Defines the initial number of worker processes created at startup.
  • pm.max_children: Limits the total number of child processes.

See Also[edit | edit source]