0

I am trying to optimize the parameters of PHP-FPM on a VPS with multiple domains. Each domain is configured with its own user/group, NGINX uses different PHP-FPM sockets. For each domain I have configured the right user/group.

I found out that the memory usage was too high, the cause was a bad configuration of the children/server parameters on PHP-FPM.

The configuration for each site is as follows (relevant part only):

pm = dynamic pm.max_children = 6 pm.start_servers = 2 pm.min_spare_servers = 2 pm.max_spare_servers = 4 pm.max_requests = 300 

There are 11 domains configured, with 6 GB of total RAM assigned. Max memory usage should be less than 64 MB for each PHP-FPM instance (htop shows a max of 50 MB usage), at max usage I should reach ~4 GB of RAM.

I think I am limiting max_children way too much, how can I find out the best value? I guess checking the real hits/days on each site will help finding those values? Am I missing some php-fpm "global" parameter?

EDIT:

What about:

; The maximum number of processes FPM will fork. This has been design to control ; the global number of processes when using dynamic PM within a lot of pools. ; Use it with caution. ; Note: A value of 0 indicates no limit ; Default Value: 0 ; process.max = 128 

in /etc/php-fpm.conf? Considering the number of domains on the server i could increase the max_children and add a limit to the global process spawned, right?

1 Answer 1

0

Was the machine swapping?

Your children configuration seems ok, if only a bit too conservative. Indeed, with max children == 6 and considering 11 domains you should be using max 4224MiB RAM so you wouldn't be touching swap at all.

Another thing, with so few children and:

pm.max_requests = 300 

Even under light traffic you'll be spawning and killing PHP processes, do you suspect memory leaks in your PHP version or applicatoins hosted?

It's difficult to give a complete answer without some more info like average memory consumption of your PHP processees, number of hits per second for php scripts ecc.

Another thing, check your swappines setting in

/proc/sys/vm/swappiness 
2
  • Memory leak should not be a problem, they are nearly all light wordpress sites. Average memory consumption is 40 MB, with spikes of 50/60MB on some sites. I always thought swapping was not a good thing, that's why I went with those numbers. Commented Sep 30, 2016 at 10:39
  • Then you can up pm.max_requests to something more, 300 means after 300 requests the child gets killed and spawned another. I have it setup at 50000, but there is no magic bullet Commented Sep 30, 2016 at 10:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.