Learn about Centmin Mod LEMP Stack today
Become a Member

PHP-FPM PHP-FPM pm.max_children

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Ne0, Oct 30, 2017.

  1. Ne0

    Ne0 New Member

    3
    2
    3
    Oct 13, 2017
    Ratings:
    +2
    Local Time:
    8:44 PM
    1.10
    Percona 5.5
    Hi,

    I'm using nginx+PHP 7 for running a Xenforo forum, however i'm experiencing problems with pm.max_children limit reached errors.

    php -v
    Code:
    PHP 7.1.11 (fpm-fcgi) (built: Oct 25 2017 10:39:04)
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
        with Zend OPcache v7.1.11, Copyright (c) 1999-2017, by Zend Technologies
    php-fpm.conf:
    Code:
    pm = dynamic
    pm.max_children = 384
    pm.start_servers = 5
    pm.min_spare_servers = 5
    ;pm.process_idle_timeout = 10s;
    ;pm.max_requests = 500
    Code:
    [29-Oct-2017 18:19:17] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 152 total children
    
    I was wondering if is normal and a good idea to keep raising more this setting ? From what i could see based on the default values 384 workers is insane.

    The forum has 4000-5000 online users with 15m cookie timeout.

    Thank you!
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,606
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,297
    Local Time:
    9:44 AM
    Nginx 1.13.x
    MariaDB 5.5
    Centmin Mod is provide as is, so short of scripted related bugs or issues, any further optimisation to the web stack components - nginx, php-fpm, mariadb mysql, csf firewall etc or web app specific configurations are left to the Centmin Mod user to deal with. So I do not provide any free support for such.

    Bad gateway 502 /504 timeouts are usually related to Nginx timing out waiting on PHP-FPM to respond as PHP-FPM is overloaded or overwhelmed with requests, so may need to tune PHP-FPM values. It also maybe due to PHP-FPM in turn being queued and backed up waiting on MariaDB MySQL server to respond - so also need to look at MySQL.

    You'll need to tune your PHP-FPM settings with php-fpm main pool config file at /usr/local/etc/php-fpm.conf (overview of config files) and this is left up to end user to do but here's a thread for starters to enable php status page output outlined at

    Checking PHP-FPM etc logs



    You'll also need to check into your PHP-FPM, Nginx and MariaDB logs which you can find as outlined at How to troubleshoot Centmin Mod initial install issues

    Server logs include Nginx, PHP-FPM, MariaDB MySQL error logs as well as others. You can find your Centmin Mod install/menu logs at FAQ 7 and server logs at FAQ 19 at Centmin Mod FAQ (most up to date info in FAQ so always read that first). Spoiler tag below has info too but may not be up to date.

    Some of Centmin Mod's installed software will have their own access and error logs which maybe useful for diagnosing errors or give info, notes, or warning notices.

    Note: There's no support provided by me for diagnosing such errors which may occur for various reasons including misconfiguration of installed php/mysql scripts or applications.

    In SSH2 telnet you can use tail command to view the last X number of lines in the file.

    For example for viewing last 10 lines in the file for:

    For Nginx access and error logs:
    Code:
      tail -10 /usr/local/nginx/logs/access.log
      tail -10 /usr/local/nginx/logs/error.log
    
    For specific domainname.com access and error log:
    Code:
      tail -10 /home/nginx/domains/domainname.com/log/access.log
      tail -10 /home/nginx/domains/domainname.com/log/error.log
    
    For other system error logs located at /var/log:

    list /var/log files in ascending time order so the most recently modified files are at the bottom
    Code:
      ls -lhrt /var/log
    
    Code:
    total 2.7M
    -rw------- 1 root  root    0 Aug 29 15:33 tallylog
    -rw------- 1 root  root    0 Aug 29 15:33 spooler
    drwx------ 3 root  root 4.0K Aug 29 15:35 samba
    drwxr-xr-x 2 root  root 4.0K Aug 29 15:35 mail
    -rw-r--r-- 1 root  500     0 Oct  8 18:13 dmesg.old
    -rw------- 1 root  500     0 Oct  8 18:13 boot.log
    -rw-r--r-- 1 root  500     0 Oct  8 18:14 dmesg
    drwx------ 2 root  root 4.0K Oct  8 18:14 httpd
    drwxr-xr-x 2 root  root 4.0K Oct  8 19:08 php-fpm
    -rw-rw---- 1 mysql root 2.3K Oct  9 12:38 mysqld.log
    -rw------- 1 root  root 9.2K Oct 26 10:48 yum.log
    -rw------- 1 root  utmp  94K Nov  7 22:59 btmp
    drwxr-xr-x 2 root  root 4.0K Nov  8 00:00 sa
    -rw------- 1 root  root 269K Nov  8 21:39 messages
    -rw------- 1 root  root 110K Nov  8 23:08 secure
    -rw-rw-r-- 1 root  utmp  43K Nov  8 23:08 wtmp
    -rw-r--r-- 1 root  root 144K Nov  8 23:08 lastlog
    -rw------- 1 root  root  69K Nov  8 23:08 lfd.log
    -rw------- 1 root  root 332K Nov  8 23:08 maillog
    -rw------- 1 root  500  1.6M Nov  8 23:10 cron
    
    For PHP-FPM error log:
    Code:
      tail -10 /var/log/php-fpm/www-error.log
    
    and/or
    Code:
      /var/log/php-fpm/www-php.error.log
    
    For MySQL / MariaDB error log:
    Code:
      tail -10 /var/log/mysqld.log
    
    For CSF firewall LFD log:
    Code:
      tail -10 /var/log/lfd.log
    
    For Mail log:
    Code:
      tail -10 /var/log/maillog
    
    For Cron job logs:
    Code:
      tail -10 /var/log/cron
    

    How to edit php.ini and php-fpm configuration files ?



    Centmin Mod install created command short cuts outlined here to allow you to quickly edit your /usr/local/lib/php.ini file and your /usr/local/etc/php-fpm.conf file. Full list of command shortcuts below:
    • Edit php.ini = phpedit ( /usr/local/lib/php.ini )
    • Edit my.cnf = mycnf ( /etc/my.cnf )
    • Edit php-fpm.conf = fpmconf ( /usr/local/etc/php-fpm.conf )
    • Edit nginx.conf = nginxconf ( /usr/local/nginx/conf/nginx.conf )
    • Edit (nginx) virtual.conf = vhostconf - only edits /usr/local/nginx/conf/conf.d/virtual.conf not the additional vhost domain.com.conf files added later
    • Edit (nginx) php.conf = phpinc ( /usr/local/nginx/conf/php.conf )
    • Edit (nginx) drop.conf = dropinc ( /usr/local/nginx/conf/drop.conf )
    • Edit (nginx) staticfiles.conf = statfilesinc ( /usr/local/nginx/conf/staticfiles.conf )
    • nginx stop/start/restart = ngxstop/ngxstart/ngxrestart
    • php-fpm stop/start/restart = fpmstop/fpmstart/fpmrestart
    • mysql stop/start/restart = mysqlstop/mysqlstart/mysqlrestart
    • nginx + php-fpm stop/start/restart = npstop/npstart/nprestart
    • memcached stop/start/restart =memcachedstop/memcachedstart/memcachedrestart
    • csf stop/start/restart = csfstop/csfstart/csfrestart

    Troubleshooting Tools



    However, there's many linux tools and scripts that can help you figure out what was causing the load issues and when.

    Tools and commands you will want to read up on and learn for basic system admin tasks and troubleshooting.
    Notes:
    However, Centmin Mod users are free to help each other out and ask questions or give answers on this community forum. My hopes are that this community forum evolves so that more veteran long time Centmin Mod users help new Centmin Mod users out :)
     
  3. eva2000

    eva2000 Administrator Staff Member

    30,606
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,297
    Local Time:
    9:44 AM
    Nginx 1.13.x
    MariaDB 5.5
    was that set by you or centmin mod 123.09beta01 auto tuned defaults ? how many cpu cores does the server have from command
    Code (Text):
    grep -c "processor" /proc/cpuinfo
    

    how much memory available
    Code (Text):
    free -m
    

    Code (Text):
    cat /proc/meminfo
    
     
    • Informative Informative x 1
  4. Ne0

    Ne0 New Member

    3
    2
    3
    Oct 13, 2017
    Ratings:
    +2
    Local Time:
    8:44 PM
    1.10
    Percona 5.5
    Thanks for the reply :)

    I still do not use centminmod, this is just a plain CentOS 6 server with PHP 7.1 installed from remi repo + nginx + Percona MySQL 5.6.

    Code:
    # grep -c "processor" /proc/cpuinfo
    12
    
    Code:
    # cat /proc/meminfo
    MemTotal:       32776540 kB
    MemFree:          898872 kB
    Buffers:          775668 kB
    Cached:          4840568 kB
    SwapCached:        58920 kB
    Active:         27163296 kB
    Inactive:        4176680 kB
    Active(anon):   24910080 kB
    Inactive(anon):  1901668 kB
    Active(file):    2253216 kB
    Inactive(file):  2275012 kB
    Unevictable:           0 kB
    Mlocked:               0 kB
    SwapTotal:       1048568 kB
    SwapFree:           6172 kB
    Dirty:              3304 kB
    Writeback:             0 kB
    AnonPages:      25667004 kB
    Mapped:          1394388 kB
    Shmem:           1087888 kB
    Slab:             216384 kB
    SReclaimable:     155976 kB
    SUnreclaim:        60408 kB
    KernelStack:        9040 kB
    PageTables:        84512 kB
    NFS_Unstable:          0 kB
    Bounce:                0 kB
    WritebackTmp:          0 kB
    CommitLimit:    17436836 kB
    Committed_AS:   29526692 kB
    VmallocTotal:   34359738367 kB
    VmallocUsed:      329880 kB
    VmallocChunk:   34359372744 kB
    HardwareCorrupted:     0 kB
    AnonHugePages:  24942592 kB
    HugePages_Total:       0
    HugePages_Free:        0
    HugePages_Rsvd:        0
    HugePages_Surp:        0
    Hugepagesize:       2048 kB
    DirectMap4k:        4096 kB
    DirectMap2M:     2027520 kB
    DirectMap1G:    31457280 kB
    Code:
    top - 05:55:27 up 1 day,  2:18,  1 user,  load average: 0.92, 1.04, 1.01
    Tasks: 312 total,   2 running, 310 sleeping,   0 stopped,   0 zombie
    Cpu(s): 10.9%us,  1.3%sy,  0.0%ni, 87.0%id,  0.6%wa,  0.0%hi,  0.3%si,  0.0%st
    Mem:  32776540k total, 31963104k used,   813436k free,   777936k buffers
    Swap:  1048568k total,  1041796k used,     6772k free,  4919756k cached
    The load average is normal and reasonable even on peak times, however when the server reach the children limit i start to see 502 bad gateway errors as php takes so long to respond due to this issue.

    Maybe @RoldanLT could share his php-fpm config since it runs a forum with similar numbers than mine.

    @Jon Snow

    I do not have permissions to reply in user profiles, anyway here are the server specs and config ;)
    Intel Xeon D-1531
    32 GB RAM
    4 x 250 GB SSD
    nginx/1.12.2
    PHP 7.1.11 + OpCache
    Percona MySQL 5.6
    memcached
     
    Last edited: Oct 30, 2017
    • Like Like x 1
  5. Jimmy

    Jimmy Premium Member Premium Member

    1,138
    252
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +609
    Local Time:
    6:44 PM
    1.13.x
    MariaDB 10.1.x
    You're not even using centmin mod?
     
  6. eva2000

    eva2000 Administrator Staff Member

    30,606
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,297
    Local Time:
    9:44 AM
    Nginx 1.13.x
    MariaDB 5.5
    @Ne0 the forums here are for Centmin Mod related LEMP setups really ;)
     
    • Winner Winner x 1
  7. RoldanLT

    RoldanLT Well-Known Member

    3,936
    961
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,312
    Local Time:
    7:44 AM
    1.11
    10.2
    This is somewhat slow CPU for PHP-FPM.

    Try this config:

    Code:
    pm = dynamic
    pm.max_children = 36
    pm.start_servers = 12
    pm.min_spare_servers = 6
    pm.max_spare_servers = 24
    pm.max_requests = 1000
    
    request_terminate_timeout = 60s
    
    php_admin_value[memory_limit] = 512M