Applicable to:
- Plesk for Linux
Question
How to calculate pm.max_children value on a Plesk server?
Answer
-
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 help to determine the memory used by each (PHP-FPM) child process:
# ps -ylC php-fpm --sort:rss
S UID PID PPID C PRI NI RSS SZ WCHAN TTY TIME CMD
S 0 931 1 0 80 0 87040 99039 ep_pol ? 00:00:00 php-fpmNote: The RSS column shows non-swapped physical memory usage by PHP-FPM processes in kiloBytes.
- 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.