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

PHP-FPM What's the reason fpmstop to be very slow?

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by rdan, Nov 24, 2018.

Tags:
  1. rdan

    rdan Well-Known Member

    4,549
    1,090
    113
    May 25, 2014
    Ratings:
    +1,591
    Local Time:
    2:46 AM
    Mainline
    10.2
  2. eva2000

    eva2000 Administrator Staff Member

    40,620
    9,015
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,881
    Local Time:
    4:46 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    nope it won't :)
    Code (Text):
    time fpmstop
    Redirecting to /bin/systemctl stop php-fpm.service
    
    real    0m0.317s
    user    0m0.040s
    sys     0m0.068s
     
    • Informative Informative x 2
  3. rdan

    rdan Well-Known Member

    4,549
    1,090
    113
    May 25, 2014
    Ratings:
    +1,591
    Local Time:
    2:46 AM
    Mainline
    10.2
    process_control_timeout = 1s
    has no downside? :/

    Afraid to try this as this server will be use extensively soon.
     
    style="display:inline-block;min-width:400px;max-width:970px;width:95%;height:90px" data-ad-client="ca-pub-6669518204467592" data-ad-slot="4024536743" data-ad-format="auto">
  4. rdan

    rdan Well-Known Member

    4,549
    1,090
    113
    May 25, 2014
    Ratings:
    +1,591
    Local Time:
    2:46 AM
    Mainline
    10.2
    By the way, why we didn't enable/configure?
    process.priority = -19 (highest priority) (maybe will not work with us since it's run by nginx)
    events.mechanism = epoll
     
  5. eva2000

    eva2000 Administrator Staff Member

    40,620
    9,015
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,881
    Local Time:
    4:46 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    you can try it yourself and see if it helps.
    probably best to let php-fpm auto determine it
    It can be problematic as php-fpm child processes may not have enough time to complete their work before being shutdown. Thus resulting in PHP-FPM 502 gateway timeout errors etc. So if set that low you would either need to ensure all php-fpm processes have completed their work before issuing a restart or use reload instead restart

    reload service command completes immediately but tells php processes to wait it seems until process_control_timeout if you time the fpmreload command and inspect php-fpm master/child process ids at 9 seconds after fpmreload and 11 seconds after fpmreload you see on 11th second the process ids for php-fpm process change (so after 10s).
    Code (Text):
    time fpmreload; ps xao pid,ppid,command | grep 'php-fpm[:]'; sleep 9; ps xao pid,ppid,command | grep 'php-fpm[:]'; sleep 2; ps xao pid,ppid,command | grep 'php-fpm[:]';
    Reload service php-fpm  done
    
    real    0m0.013s
    user    0m0.007s
    sys     0m0.006s
    19650     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
    19651 19650 php-fpm: pool www
    19652 19650 php-fpm: pool www
    19653 19650 php-fpm: pool www
    19654 19650 php-fpm: pool www
    19655 19650 php-fpm: pool www
    19656 19650 php-fpm: pool www
    19657 19650 php-fpm: pool www
    19658 19650 php-fpm: pool www
    19650     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
    19651 19650 php-fpm: pool www
    19652 19650 php-fpm: pool www
    19653 19650 php-fpm: pool www
    19654 19650 php-fpm: pool www
    19655 19650 php-fpm: pool www
    19656 19650 php-fpm: pool www
    19657 19650 php-fpm: pool www
    19658 19650 php-fpm: pool www
    19687     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
    19688 19687 php-fpm: pool www
    19689 19687 php-fpm: pool www
    19690 19687 php-fpm: pool www
    19691 19687 php-fpm: pool www
    19692 19687 php-fpm: pool www
    19693 19687 php-fpm: pool www
    19694 19687 php-fpm: pool www
    19695 19687 php-fpm: pool www
    

    versus fpmrestart only completes the actual command after that 10s when using static or dynamic process manager instead of default ondemand where php-fpm process ids change immediately after end of fpmrestart (which still waits that 10s)
    Code (Text):
    ps xao pid,ppid,command | grep 'php-fpm[:]'; time fpmrestart; ps xao pid,ppid,command | grep 'php-fpm[:]'; sleep 9; ps xao pid,ppid,command | grep 'php-fpm[:]'; sleep 2; ps xao pid,ppid,command | grep 'php-fpm[:]';
    19687     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
    19688 19687 php-fpm: pool www
    19689 19687 php-fpm: pool www
    19690 19687 php-fpm: pool www
    19691 19687 php-fpm: pool www
    19692 19687 php-fpm: pool www
    19693 19687 php-fpm: pool www
    19694 19687 php-fpm: pool www
    19695 19687 php-fpm: pool www
    Gracefully shutting down php-fpm .......... done
    Starting php-fpm  done
    
    real    0m10.348s
    user    0m0.102s
    sys     0m0.059s
    19929     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
    19930 19929 php-fpm: pool www
    19931 19929 php-fpm: pool www
    19932 19929 php-fpm: pool www
    19933 19929 php-fpm: pool www
    19934 19929 php-fpm: pool www
    19935 19929 php-fpm: pool www
    19936 19929 php-fpm: pool www
    19937 19929 php-fpm: pool www
    19929     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
    19930 19929 php-fpm: pool www
    19931 19929 php-fpm: pool www
    19932 19929 php-fpm: pool www
    19933 19929 php-fpm: pool www
    19934 19929 php-fpm: pool www
    19935 19929 php-fpm: pool www
    19936 19929 php-fpm: pool www
    19937 19929 php-fpm: pool www
    19929     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
    19930 19929 php-fpm: pool www
    19931 19929 php-fpm: pool www
    19932 19929 php-fpm: pool www
    19933 19929 php-fpm: pool www
    19934 19929 php-fpm: pool www
    19935 19929 php-fpm: pool www
    19936 19929 php-fpm: pool www
    19937 19929 php-fpm: pool www
    

    compare that to centos 7 systemd based php-fpm workaround mentioned, the php-fpm processes change immediately on completion of fpmrestart command which only takes 0.344s
    Code (Text):
    ps xao pid,ppid,command | grep 'php-fpm[:]'; time fpmrestart; ps xao pid,ppid,command | grep 'php-fpm[:]'; sleep 9; ps xao pid,ppid,command | grep 'php-fpm[:]'; sleep 2; ps xao pid,ppid,command | grep 'php-fpm[:]';
     5704     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
     5705  5704 php-fpm: pool www
     5706  5704 php-fpm: pool www
     5707  5704 php-fpm: pool www
     5708  5704 php-fpm: pool www
     5709  5704 php-fpm: pool www
     5710  5704 php-fpm: pool www
     5711  5704 php-fpm: pool www
     5712  5704 php-fpm: pool www
    Redirecting to /bin/systemctl restart php-fpm.service
    
    real    0m0.344s
    user    0m0.038s
    sys     0m0.035s
     5815     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
     5816  5815 php-fpm: pool www
     5817  5815 php-fpm: pool www
     5818  5815 php-fpm: pool www
     5819  5815 php-fpm: pool www
     5820  5815 php-fpm: pool www
     5821  5815 php-fpm: pool www
     5822  5815 php-fpm: pool www
     5823  5815 php-fpm: pool www
     5815     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
     5816  5815 php-fpm: pool www
     5817  5815 php-fpm: pool www
     5818  5815 php-fpm: pool www
     5819  5815 php-fpm: pool www
     5820  5815 php-fpm: pool www
     5821  5815 php-fpm: pool www
     5822  5815 php-fpm: pool www
     5823  5815 php-fpm: pool www
     5815     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
     5816  5815 php-fpm: pool www
     5817  5815 php-fpm: pool www
     5818  5815 php-fpm: pool www
     5819  5815 php-fpm: pool www
     5820  5815 php-fpm: pool www
     5821  5815 php-fpm: pool www
     5822  5815 php-fpm: pool www
     5823  5815 php-fpm: pool www
    

    but restart kills PHP processes immediately so get 502 if you still have php-fpm worker processes doing work - for graceful restart always use reload

    with CentOS 7 systemd PHP-FPM reload which waits that 10s
    Code (Text):
    time fpmreload; ps xao pid,ppid,command | grep 'php-fpm[:]'; sleep 2; ps xao pid,ppid,command | grep 'php-fpm[:]'; sleep 9; ps xao pid,ppid,command | grep 'php-fpm[:]'; 
    Redirecting to /bin/systemctl reload php-fpm.service
    
    real    0m0.182s
    user    0m0.033s
    sys     0m0.040s
    20150     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
    20151 20150 php-fpm: pool www
    20152 20150 php-fpm: pool www
    20153 20150 php-fpm: pool www
    20154 20150 php-fpm: pool www
    20155 20150 php-fpm: pool www
    20156 20150 php-fpm: pool www
    20157 20150 php-fpm: pool www
    20158 20150 php-fpm: pool www
    20150     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
    20151 20150 php-fpm: pool www
    20152 20150 php-fpm: pool www
    20153 20150 php-fpm: pool www
    20154 20150 php-fpm: pool www
    20155 20150 php-fpm: pool www
    20156 20150 php-fpm: pool www
    20157 20150 php-fpm: pool www
    20158 20150 php-fpm: pool www
    20231     1 php-fpm: master process (/usr/local/etc/php-fpm.conf)
    20232 20231 php-fpm: pool www
    20233 20231 php-fpm: pool www
    20234 20231 php-fpm: pool www
    20235 20231 php-fpm: pool www
    20236 20231 php-fpm: pool www
    20237 20231 php-fpm: pool www
    20238 20231 php-fpm: pool www
    20239 20231 php-fpm: pool www
    

    you can always revert to old init.d php-fpm service method if switching systemd doesn't work. I've added to php-systemd.sh script a restore command to revert to init.d php-fpm service method too if systemd php-fpm service doesn't work 100%

    switch to systemd php-fpm service
    Code (Text):
    curl -sL https://gist.githubusercontent.com/centminmod/a84a86775925ea558fece1f0ac130be3/raw/php-systemd.sh | bash
    

    Code (Text):
    curl -sL https://gist.githubusercontent.com/centminmod/a84a86775925ea558fece1f0ac130be3/raw/php-systemd.sh | bash
    Gracefully shutting down php-fpm ..... done
    systemctl daemon-reload
    
    systemctl restart php-fpm
    
    systemctl enable php-fpm
    
    systemctl status php-fpm
    ● php-fpm.service - PHP FastCGI Process Manager
       Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
      Drop-In: /etc/systemd/system/php-fpm.service.d
               └─limit.conf
       Active: active (running) since Sat 2019-01-26 06:17:50 UTC; 88ms ago
     Main PID: 8360 (php-fpm)
       CGroup: /system.slice/php-fpm.service
               ├─8360 php-fpm: master process (/usr/local/etc/php-fpm.conf)
               ├─8361 php-fpm: pool www
               ├─8362 php-fpm: pool www
               ├─8363 php-fpm: pool www
               ├─8364 php-fpm: pool www
               ├─8365 php-fpm: pool www
               ├─8366 php-fpm: pool www
               ├─8367 php-fpm: pool www
               └─8368 php-fpm: pool www
    
    Jan 26 06:17:50 test.com systemd[1]: Starting PHP FastCGI Process Manager...
    Jan 26 06:17:50 test.com systemd[1]: Started PHP FastCGI Process Manager.
    

    restore to init.d php-fpm service method
    Code (Text):
    curl -sL https://gist.githubusercontent.com/centminmod/a84a86775925ea558fece1f0ac130be3/raw/php-systemd.sh | bash -s restore
    

    Code (Text):
    curl -sL https://gist.githubusercontent.com/centminmod/a84a86775925ea558fece1f0ac130be3/raw/php-systemd.sh | bash -s restore
    systemctl daemon-reload
    
    service php-fpm start
    Starting php-fpm  done
    
    chkconfig on
    
    service php-fpm status
    php-fpm (pid 8697) is running...
    


    To discuss php-systemd.sh itself, started a thread at CentOS 7 Proper PHP-FPM systemd service file
     
    Last edited: Jan 26, 2019
    • Informative Informative x 1