0

In my PHP-FPM configuration I have 3 Pools, the eg: Config is:

;;;;;;;;;;;;;;;;;;;;;;;
; Pool 1              ;
;;;;;;;;;;;;;;;;;;;;;;;
[www1]
user = www
group = www

listen = /tmp/php-fpm1.sock;
listen.backlog = -1
listen.owner = www
listen.group = www
listen.mode = 0666
pm = dynamic
pm.max_children = 40
pm.start_servers = 6
pm.min_spare_servers = 6
pm.max_spare_servers = 12
pm.max_requests = 250
slowlog = /var/log/php/$pool.log.slow
request_slowlog_timeout = 5s
request_terminate_timeout = 120s
rlimit_files = 131072

;;;;;;;;;;;;;;;;;;;;;;;
; Pool 2              ;
;;;;;;;;;;;;;;;;;;;;;;;
[www2]
user = www
group = www

listen = /tmp/php-fpm2.sock;
listen.backlog = -1
listen.owner = www
listen.group = www
listen.mode = 0666
pm = dynamic
pm.max_children = 40
pm.start_servers = 6
pm.min_spare_servers = 6
pm.max_spare_servers = 12
pm.max_requests = 250
slowlog = /var/log/php/$pool.log.slow
request_slowlog_timeout = 5s
request_terminate_timeout = 120s
rlimit_files = 131072

;;;;;;;;;;;;;;;;;;;;;;;
; Pool 3              ;
;;;;;;;;;;;;;;;;;;;;;;;
[www3]
user = www
group = www

listen = /tmp/php-fpm3.sock;
listen.backlog = -1
listen.owner = www
listen.group = www
listen.mode = 0666
pm = dynamic
pm.max_children = 40
pm.start_servers = 6
pm.min_spare_servers = 6
pm.max_spare_servers = 12
pm.max_requests = 250
slowlog = /var/log/php/$pool.log.slow
request_slowlog_timeout = 5s
request_terminate_timeout = 120s
rlimit_files = 131072

I calculated the pm.max_children processes according to some example calculations on the web like 40 x 40 Mb = 1600 Mb. I have separated 4 GB of RAM for PHP, now according to the calculations 40 Child Processes via one socket, and I have total of 3 sockets in my Nginx and FPM configuration. My doubt is about the amount of memory consumption by those child processes.

I tried to create high load in the server via httperf hog and siege but I could not calculate the accurate memory usage by all the PHP processes (other processes like MySQL and Nginx were also running). And all the sockets were in use, So, I seek guidance from anyone who have done this before or know how exactly the pm.max_children in PHP Works.

Since I have 3 Pools/sockets with 40 child processes does that count to 3 x 40 x 40 Mb of Memory usage ? or it is just like 40 Max. Child processes sharing 3 sockets (and the total memory usage is just 40 x 40 Mb) ?

4
  • From where does come the 40Mb figure per child?
    – Déjà vu
    Commented Mar 23, 2013 at 7:53
  • Assumption that one child process will take 40 MB of memory.... Usually what I read is people assume 30-40 MB
    – user156477
    Commented Mar 23, 2013 at 14:06
  • I'd say the answer is 3 x 40 x 40 but cannot confirm for sure
    – Déjà vu
    Commented Mar 23, 2013 at 14:09
  • 1
    To calculate the total memory size used by all php-fpm worker processes: ps aux | grep php-fpm | awk '{print $2}' | xargs pmap | grep total | awk '{print substr($0, 1, length($0)-1)}' | awk '{print $2}' | awk '{total = total + $1}END{print total}' - You can divide that number by the number of worker processes to get the average size used by a php-fpm process Commented Sep 5, 2017 at 16:55

2 Answers 2

1

There is no simple answer to this question. A single memory figure is hard to put onto a running PHP-FPM process.

First of all, memory usage of one process is usually divided into multiple parts (usually shared and unshared memory). The usage of shared memory is greatly dependent on the usage of the libraries in PHP.

If the guidance you need is to optimize the correct settings for a busy web-server I can recommend the following:

  • Stick to safe values while going into production.
  • Use busy production times to stretch the limits and see how it handles (production usage is the best indicator).
  • Reaping often used processes give a fresh start for a process unshared memory.
  • Stop focusing on memory usage per process.
  • Run benchmarking tools and load generators to find the limits of your system.

I think you are seeking the optimal memory settings fitting the dimensions of your server. Keep in mind that the duration of one request also has a great impact on the amount of processes required to keep your web server responsive.

A good reference to measuring memory of a process is on stackoverflow.

0

The following python script would be helpful as it'll show you the total amount of memory used by php-fpm by all the children, the total no. of children, along with shared/private memory used during the load testing:

http://www.pixelbeat.org/scripts/ps_mem.py

You must log in to answer this question.