Applicable to:
- Plesk for Linux
Question
How to calculate pm.max_children value on a Plesk server?
Answer
- Connect to the server via SSH.
- Calculate and change the value of the parameter
pm.max_childrenbased on the amount of RAM on the system and the number of CPU cores (Each PHP-FPM process uses a CPU to execute PHP code. These processes are executed independently by the OS and compete for access to processor cores.).
The PHP script can:
- CPU-bound: Perform arithmetic, cycles, data conversions → loads CPU (CPU Load High)
- I/O-bound: Perform I/O waits (working with database, network, files) → CPU "waits", load drops (CPU Load Low/intermittent)
If you have a lot of CPU-bound logic, then: Number of cores = parallelism ceiling.
If you have a lot of I/O-bound logic, then: You can run more processes than cores (sometimes ×2–×4 of the number of cores), and everything will be ok.
This impacts CPU (and memory) load, especially during DDoS or peak access. -
The following command will provide the number of processes, total RSS and average RSS in MB:
# ps -C php-fpm -o rss= | awk '{sum+=$1; n++} END {if (n) printf "Processes: %d | Total: %.1f MB | Avg: %.1f MB\n", n, sum/1024, sum/n/1024}'
Processes: 12 | Total: 1020 MB | Avg: 85 MB -
The following command will help to determine the number of CPU cores:
# cat /proc/cpuinfo | grep processor | wc -l
8 -
If on average each PHP-FPM process takes ~85MB of RAM on the server, the appropriate value for
pm.max_childrencan be calculated as follows:CONFIG_TEXT: pm.max_children = Total RAM dedicated to the web server / Max child process size
For example, if the server has 8GB of RAM and 6GB of RAM is planned to be allocated to the web server, then the
pm.max_childrenvalue will be the following:CONFIG_TEXT: pm.max_children = 6144MB / 85MB = 72
In this case, the number of parallel processes per 1 processor core will be about ~10 (uses by Default).
Note: The received number of children has to be distributed among all websites on the server. Keep in mind that most popular websites require more children while others, non-popular ones - less. Be sure to consider the number of cores on your server to avoid overloading the processor with too many simultaneous processes.
Example of how to divide the result between websitesThere are 3 domains on the server:
-
example.comA popular online shop. The number of visitors is very high.
-
example.netA home page of some person. The number of visitors is almost zero.
-
example.orgA little jewelry online shop that was created a month ago. The number of visitors is not high.
Is the appropriate
pm.max_childrenvalue was calculated to be 72, in this case, it is required to allocate children, for example, as follows:-
For
example.com:50 children.
-
For
example.net:2 children.
-
For
example.org:20 children.
-
- To apply changes for
pm.max_childrenvalue customize PHP settings as per the article.
Comments
For tips, I would add:
You can progressivly increase the value, and know exactly if it was too low, inside the log:
Note the first link at point 4 is "not found":
I think the right page is this:
Hello Adrian,
Thank you for the comments. The article was updated.
Please sign in to leave a comment.