Adjusting PHP-FPM Performance on a Fairly Weak Server with 2 Cores of Xeon Gold 6132
As the traffic on your webpage has recently increased, you may have noticed that your server's performance has been affected. This article will provide you with detailed information on how to adjust PHP-FPM performance on a fairly weak server with 2 cores of Xeon Gold 6132, to ensure optimal system resources usage.
Understanding PHP-FPM
PHP-FPM (FastCGI Process Manager) is a process manager for PHP applications that allows for better performance and scalability. It runs as a separate service and manages a pool of worker processes that handle incoming PHP requests. By default, PHP-FPM is configured to use a static number of worker processes, which may not be optimal for your server's resources.
Checking Current PHP-FPM Configuration
To check the current PHP-FPM configuration, you can access the /etc/php/ file, where www user and group.
Adjusting PHP-FPM Settings
To adjust PHP-FPM settings for optimal performance on a weak server, you should focus on the following settings:
pm: This setting controls the process management mode. You should use thedynamicmode, which adjusts the number of worker processes based on the current load.pm.max_children: This setting controls the maximum number of worker processes that can be started. You should set this value based on the number of available CPU cores and the amount of memory available on your server.pm.start_servers,pm.min_spare_servers, andpm.max_spare_servers: These settings control the number of worker processes that are started and kept in reserve. You should set these values based on the expected load on your server and the time it takes to start a new worker process.
Example Configuration
Here is an example configuration for a weak server with 2 CPU cores and 4 GB of memory:
[www]
user = www-data
group = www-data
listen = /run/php/php7.4-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 6
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500
This configuration sets the maximum number of worker processes to 6, which is twice the number of CPU cores. It also sets the minimum and maximum number of spare servers to 1 and 3, respectively, to ensure that there are always enough worker processes available to handle incoming requests.
Testing PHP-FPM Performance
After adjusting the PHP-FPM configuration, you should test the performance of your server to ensure that it is using system resources optimally. You can use tools such as top or htop to monitor the CPU and memory usage of your server, and tools such as ab or siege to simulate incoming traffic and measure the response time of your server.
- PHP-FPM is a process manager for PHP applications that allows for better performance and scalability.
- On a weak server with 2 CPU cores, you should adjust the PHP-FPM configuration to use the dynamic mode and set the maximum number of worker processes to twice the number of CPU cores.
- You should also set the minimum and maximum number of spare servers based on the expected load on your server and the time it takes to start a new worker process.
- After adjusting the PHP-FPM configuration, you should test the performance of your server to ensure that it is using system resources optimally.