Determining memory per child process
We need to determine how much memory per child process of php-fpm is using for calculating the final value. I use a script called ps_mem to get some statistics of my processes and memory.
# Download the script first
wget http://git.io/joLG
# and run it like this:
python ps_mem.py | grep php5
the output should give you something like this:
1.8 GiB + 145.5 MiB = 1.9 GiB php5-fpm (41)
This means php-fpm is using in total 1.9 GiB with 41 Processes . After converting the value in Megabyte, we will divide it by the number of processes. This will tell us: How much each child process (41) is consuming.
1900 MiB/41 Processes = 46.34 MiB
48.59MB memory / Processes
We can now calculate the number of process php-fpm can calculate via this simple formula:
max_children = (Total Number of Memory — 1000MB) / FPM Memory per Process
We reserved 1000MB for other process like mysql, nginx, etc.
max_children = (4000 MB — 1000 MB) / 48.59
max_children = 62.5
You can now set the pm.max_children to have maximum of 62.5.
https://www.prometsource.com/blog/optimizing-php-fpm-promet-way
Просмотров: 825