Learn about Centmin Mod LEMP Stack today
Become a Member

PHP-FPM pm.max_children

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by pamamolf, Jun 15, 2014.

  1. pamamolf

    pamamolf Well-Known Member

    2,539
    231
    63
    May 31, 2014
    Ratings:
    +394
    Local Time:
    11:55 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Hi

    I am using dynamic for php-fpm and i am trying to adjust the:

    pm.max_children = how can i find out how many php workers my site is using and how can i calculate the maximum value so my server will not die using a huge value?

    pm.start_servers =If i know how many php workers my site needs as i ak above then i know how to adjust this :)

    pm.min_spare_servers =no idea how to calculate this value :)

    pm.max_spare_servers =no idea how to calculate this value :)

    max_requests = is this per worker?


    Thanks :)
     
    Last edited: Jun 15, 2014
  2. eva2000

    eva2000 Administrator Staff Member

    29,054
    6,594
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,790
    Local Time:
    6:55 PM
    Nginx 1.13.x
    MariaDB 5.5
    I'll leave tuning up to other folks to chime in as I don't provide optimisation advice/support for Centmin Mod - the script is provided as is. I reserve optimisation work to only private paying clients usually :)

    It's best read documentation at http://www.php.net/manual/en/install.fpm.configuration.php.

    where a child is defined in the context of pm.max_children
    Although pm.max_children is also for when pm set to ondemand which is Centmin Mod PHP-FPM default.

    As to finding out how many PHP processes are in play, you need to enable your /phpstatus page as directed on official web site at http://centminmod.com/phpfpm.html#browserstatus

    For example once your /phpstatus page is setup properly, run this command whenever you want to see php-fpm usage stats:
    Code:
    lynx --dump http://127.0.0.1/phpstatus
    You'll get output like below:
    Code:
    pool: www
    process manager: static
    start time: 28/Jun/2012:21:24:51 +0400
    start since: 75
    accepted conn: 196
    listen queue: 0
    max listen queue: 0
    listen queue len: 0
    idle processes: 4
    active processes: 1
    total processes: 5
    max active processes: 1
    max children reached: 0
    each status stats are explained on official site at http://centminmod.com/phpfpm.html#browserstatus

    PHP Status explained:
    • pool - the name of the pool that is listening on the connected socket, as defined in the php-fpm config.
    • process manager - the method used by the process manager to control the number of child processes - either ondemand, dynamic or static - set on a per pool basis (in the php-fpm config) by the pm parameter.
    • start time - the date, time, and UTC offset corresponding to when the PHP-FPM server was started.
    • start since - the number of seconds that have elapsed since the PHP-FPM server was started (i.e. uptime).
    • accepted conn - the number of incoming requests that the PHP-FPM server has accepted; when a connection is accepted it is removed from the listen queue (displayed in real time).
    • listen queue - the current number of connections that have been initiated, but not yet accepted. If this value is non-zero it typically means that all the available server processes are currently busy, and there are no processes available to serve the next request. Raising pm.max_children (provided the server can handle it) should help keep this number low. This property follows from the fact that PHP-FPM listens via a socket (TCP or file based), and thus inherits some of the characteristics of sockets.
    • max listen queue - the maximum value the listen queue has reached since the server was started.
    • listen queue len - the upper limit on the number of connections that will be queued Once this limit is reached, subsequent connections will either be refused, or ignored. This value is set by the php-fpm per pool configuration option 'listen.backlog', which defaults to -1 (unlimited). However, this value is also limited by the system (sysctl) value 'net.core.somaxconn', which defaults to 128 on many Linux systems.
    • idle processes - the number of servers in the 'waiting to process' state (i.e. not currently serving a page). This value should fall between the pm.min_spare_servers and pm.max_spare_servers values when the process manager is dynamic. (updated once per second)
    • active processes - the number of servers current processing a page - the minimum is 1 (so even on a fully idle server, the result will be not read 0). (updated once per second)
    • total processes - the total number of server processes currently running; the sum of idle processes + active processes. If the process manager is static, this number will match pm.max_children. (updated once per second)
    • max active processes - the highest value that 'active processes' has reached since the php-fpm server started. This value should not exceed pm.max_children.
    • max children reached - the number of times that pm.max_children has been reached since the php-fpm server started (only applicable if the process manager is ondemand or dynamic)
     
    • Like Like x 3
  3. pamamolf

    pamamolf Well-Known Member

    2,539
    231
    63
    May 31, 2014
    Ratings:
    +394
    Local Time:
    11:55 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Ok thanks :)