PHP-FPM Pool, Child Processes and Memory Consumption

Posted by Jhilke Dai on Server Fault See other posts from Server Fault or by Jhilke Dai
Published on 2013-03-22T22:52:17Z Indexed on 2014/08/23 22:24 UTC
Read the original article Hit count: 385

Filed under:
|
|

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) ?

© Server Fault or respective owner

Related posts about php

Related posts about nginx