Get the most out of your Centmin Mod LEMP stack
Become a Member

PHP-FPM pm.max_children

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

  1. pamamolf

    pamamolf Premium Member Premium Member

    4,068
    427
    83
    May 31, 2014
    Ratings:
    +832
    Local Time:
    12:01 PM
    Nginx-1.25.x
    MariaDB 10.3.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

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    7:01 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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 PHP: Configuration - Manual.

    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 PHP-FPM - CentminMod.com LEMP Nginx web stack for CentOS

    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 PHP-FPM - CentminMod.com LEMP Nginx web stack for CentOS

    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)
     
  3. pamamolf

    pamamolf Premium Member Premium Member

    4,068
    427
    83
    May 31, 2014
    Ratings:
    +832
    Local Time:
    12:01 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Ok thanks :)