PHP-FPM pm.max children
IT 위키
Fortify (토론 | 기여)님의 2024년 12월 1일 (일) 13:22 판 (새 문서: '''pm.max_children''' is a directive in PHP-FPM (FastCGI Process Manager) configuration that specifies the maximum number of child processes that can be created to handle incoming requests. This setting is critical for managing server resources and ensuring that PHP-FPM can efficiently handle concurrent traffic without overloading the server. ==Overview== *The `pm.max_children` directive determines the upper limit on the number of simultaneous PHP-FPM worker processes. *When the...)
pm.max_children is a directive in PHP-FPM (FastCGI Process Manager) configuration that specifies the maximum number of child processes that can be created to handle incoming requests. This setting is critical for managing server resources and ensuring that PHP-FPM can efficiently handle concurrent traffic without overloading the server.
Overview[편집 | 원본 편집]
- The `pm.max_children` directive determines the upper limit on the number of simultaneous PHP-FPM worker processes.
- When the number of incoming requests exceeds `pm.max_children`, additional requests are queued until a process becomes available.
- This setting is applicable for all process management modes (`dynamic`, `static`, and `ondemand`).
Syntax[편집 | 원본 편집]
The directive is configured in the PHP-FPM pool configuration file (e.g., `www.conf`).
pm = dynamic
pm.max_children = 50
How It Works[편집 | 원본 편집]
- In `dynamic` mode:
- Child processes are created as needed, but the total number of processes cannot exceed `pm.max_children`.
- In `static` mode:
- The server always creates exactly `pm.max_children` processes.
- In `ondemand` mode:
- Processes are spawned only when requests arrive, but the total number of processes is still limited by `pm.max_children`.
Configuration Example[편집 | 원본 편집]
Here’s an example configuration for a PHP-FPM pool:
[www]
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 10
Explanation[편집 | 원본 편집]
- pm = dynamic: Enables dynamic process management mode.
- pm.max_children = 50: Limits the total number of worker processes to 50.
- pm.start_servers = 5: Starts with 5 worker processes when PHP-FPM initializes.
- pm.min_spare_servers = 2: Maintains at least 2 idle processes.
- pm.max_spare_servers = 10: Limits the number of idle processes to 10.
Key Considerations[편집 | 원본 편집]
- Server Resources: Setting `pm.max_children` too high can lead to excessive memory and CPU usage, potentially causing server instability.
- Application Demand: The value should be high enough to handle peak traffic without excessive queuing or delays.
- Queue Length: When the number of requests exceeds `pm.max_children`, requests are queued. Monitor the queue length to determine if the value needs adjustment.
How to Calculate pm.max_children[편집 | 원본 편집]
To calculate the optimal value for `pm.max_children`, consider the following:
- Available Memory: Ensure that the total memory usage of PHP-FPM processes does not exceed the server's physical memory.
- Memory Usage Per Process: Monitor the average memory usage of each PHP-FPM process using tools like `top` or `htop`.
Formula[편집 | 원본 편집]
pm.max_children = (Total RAM - Other Services Memory) / Average PHP-FPM Process Memory
Monitoring and Troubleshooting[편집 | 원본 편집]
Use the `php-fpm` status page or tools like `htop` to monitor:
- The number of active processes.
- Memory and CPU usage.
- Request queues, which indicate whether `pm.max_children` needs adjustment.
Example Issues[편집 | 원본 편집]
- 502 Bad Gateway Errors:
- Cause: Requests are queued due to insufficient child processes.
- Solution: Increase `pm.max_children` or optimize the application to reduce resource usage.
- High Memory Usage:
- Cause: `pm.max_children` is set too high for the server's available memory.
- Solution: Reduce `pm.max_children` and ensure enough resources are available.
Related Directives[편집 | 원본 편집]
- pm.start_servers: Defines the number of worker processes created on startup.
- pm.min_spare_servers: Sets the minimum number of idle worker processes.
- pm.max_spare_servers: Limits the maximum number of idle worker processes.
- pm.process_idle_timeout: Specifies the timeout for idle processes in `ondemand` mode.