php-fpm: help understanding start_servers, min_spare_servers, max_spare_servers

I'm trying to tune my php-fpm installation for my server, and I have trouble figuring out what to do with the pm.start_servers, pm.min_spare_servers and pm.max_spare_servers variables. I am using pm = dynamic

pm.max_children is perfectly clear. Each child process serves 1 web client at one time. Ok. What is a "server", then? Clearly, based on the default configuration I have, 1 server can serve more than 1 child. What is the upper limit? What should I use as rule of thumb for # of children / server? Or is it related at all? On some forum, someone was claiming that # of servers should be 2 x # of cpu cores, but I have seen recommended configurations where the number was much higher, 40-50.

Neither the PHP documentation nor the many "tuning php-fpm" articles out there have been at all helpful.


Basically the number of processes that php-fpm will have running at any time is very configurable when you set to dynamic like you do. When set to static there will ALWAYS be that many child processes running. Generally you set it to dynamic to conserve resources. Each child process can handle one request. The upper limit is dependant on how heavy your php application is and how much traffic you get. You should also calculate average the memory consumption of each child and make sure that you NEVER allow the number of children to exceed amount of ram installed on your server or you will start swapping or even have the kernel start killing processes.

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives:
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
; Note: This value is mandatory.

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?