How to calculate pm.max_children value?
- Connect to the server via SSH.
- To calculate and change the value of the parameter
pm.max_childrenbased on the amount of RAM on the system, 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-fpm
Note: The RSS column shows non-swapped physical memory usage by PHP-FPM processes in kiloBytes.
- If on an average each PHP-FPM process takes ~85MB of RAM on the server, the appropriate value for pm.max_children can be calculated as:
pm.max_children = Total RAM dedicated to the web server / Max child process size
For example, if the server has 8GB of RAM, then the
pm.max_childrenvalue will be the following:
pm.max_children = 6144MB / 85MB = 72
Note: The received number of children have to be distributed among all websites on the server. Moreover, it is required to keep in mind that most popular websites require more children while others, non-popular ones – less.
For example, there are 3 websites on the server:
A popular online shop. The number of visitors is very high.
A home page of some person which number of visitors is almost zero.
A little jewelry online shop which appeared 1 month ago. The number of visitors is not high.
In this case, it is required to allocate children, for example, as follows:
- To apply changes for
pm.max_childrenvalue follow steps from the article: How to apply PHP-FPM pool settings for all the domains?