Learn about Centmin Mod LEMP Stack today
Register Now

PHP-FPM Process Manager: ondemand, dynamic, or static

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by deltahf, Aug 29, 2014.

  1. deltahf

    deltahf Premium Member Premium Member

    585
    264
    63
    Jun 8, 2014
    Ratings:
    +486
    Local Time:
    11:44 AM
    I noticed the default setting for "pm" in php-fpm.conf is "ondemand".

    According to this post, "ondemand" is best for shared hosting environments which will have a high number of low-load pools.

    I am running a single high-traffic site on my server in one pool (I think), and that post indicates "static" would be the best for me, presumably because this means the processes always exist and don't have to be created "on demand".

    Is this a setting I should modify or should I just leave it as is?


    Thanks! :)
     
  2. Peter Downey

    Peter Downey Member

    64
    24
    8
    May 28, 2014
    Ratings:
    +27
    Local Time:
    11:44 AM
    That's probably something that you're better off benchmarking on your own for your specific setup. For what it's worth, I have mine set at ondemand.
     
  3. eva2000

    eva2000 Administrator Staff Member

    54,070
    12,176
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,734
    Local Time:
    2:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Well tuning is best left to yourself for trial and error testing as to which is better as I don't provide in depth support for tuning as Centmin Mod is provided as is.

    However, to tune PHP-FPM you would want to enable PHP status page and you can find instructions on that and general tuning from these 2 threads
    As to ondemand it's default as Centmin Mod part of the focus is on low memory based VPSes i.e. 128-512MB and ondemand provides a balance to keep memory usage low. If you have plenty of memory, then yes static is good. If you have alot of cpu threads to work with then dynamic is even better.
     
  4. eva2000

    eva2000 Administrator Staff Member

    54,070
    12,176
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,734
    Local Time:
    2:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Oh Centmin Mod PHP-FPM default max_execution_time is raised from default 30s to 60s so that might play apart in hogging PHP processes for longer PHP: Runtime Configuration - Manual

    It's auto changed on line 8 in inc/phpsededit.inc

    If your problem is with XF 1.3 - How sensitive is the image proxy to slow origin servers? | XenForo Community then lowering that value in your inc/phpsededit.inc and then in your /usr/local/lib/php.ini back to 30s might be better as you might be experiencing what I posted here. Also try Shawn's proxy addon instead Digital Point Image Proxy | XenForo Community as @RoldanLT tested it at https://community.centminmod.com/threads/testing-your-php-fpm.1224/

    edit: seems Digitalpoint Proxy Image addon doesn't work with PHP 5.6 :(

    php.ini command shortcut to launch nano text editor for the file is

    Code:
    phpedit
    FAQ 16 has a list of all command shortcuts too Centmin Mod FAQ - Menu based Nginx installer
     
    Last edited: Aug 30, 2014
  5. rdan

    rdan Well-Known Member

    5,443
    1,402
    113
    May 25, 2014
    Ratings:
    +2,194
    Local Time:
    12:44 AM
    Mainline
    10.2
  6. deltahf

    deltahf Premium Member Premium Member

    585
    264
    63
    Jun 8, 2014
    Ratings:
    +486
    Local Time:
    11:44 AM
    Thanks so much for the links, @eva2000...those shortcuts are awesome, too. Good idea to reduce the max_execution_time (and yes, that's my thread at XenForo). :)

    I have a good amount of RAM (16GB) and decided to go with a static process manager config, then bumped my pm.max_children to 70. Immediately, it felt like I had just hit the TURBO button on my server, and my XenForo install felt faster than ever (and it was already very quick!). Benchmarks from loader.io testing also showed that the site was able to handle many more simultaneous connections than before. :D

    There does seem to be some conflicting advice out there regarding how to calculate the optimal max_children setting for your server, though, so I'm not sure if I have done the right thing there. This guy offers a nice formula to go by (I calculated mine with conservative RAM usage relative to what I actually have), but then I've also read here and elsewhere that you don't really benefit from having more children than cores available in your system (I have 8), which obviously makes a lot of sense.

    Nevertheless, I do seem to be using a fair amount of the children according to my phpstats.

    Code:
    pool: www
    process manager: static
    start time: 29/Aug/2014:21:07:06 -0400
    start since: 57112
    accepted conn: 745579
    listen queue: 0
    max listen queue: 1
    listen queue len: 128
    idle processes: 66
    active processes: 4
    total processes: 70
    max active processes: 54
    max children reached: 0
    
     
  7. rdan

    rdan Well-Known Member

    5,443
    1,402
    113
    May 25, 2014
    Ratings:
    +2,194
    Local Time:
    12:44 AM
    Mainline
    10.2
    pm.max_children having 70 is too much for your server having 8 cores.
    That's what I learn from @Floren :)
     
  8. deltahf

    deltahf Premium Member Premium Member

    585
    264
    63
    Jun 8, 2014
    Ratings:
    +486
    Local Time:
    11:44 AM
  9. rdan

    rdan Well-Known Member

    5,443
    1,402
    113
    May 25, 2014
    Ratings:
    +2,194
    Local Time:
    12:44 AM
    Mainline
    10.2
  10. deltahf

    deltahf Premium Member Premium Member

    585
    264
    63
    Jun 8, 2014
    Ratings:
    +486
    Local Time:
    11:44 AM
    Thanks so much for sharing that link, I'm convinced. :)

    I've updated my configuration and will see how it goes.
    Code:
    pm = static
    pm.max_children = 8
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 8
    pm.min_spare_servers = 8
    pm.max_spare_servers = 8
    pm.max_requests = 100
    No specific reason for keeping it static, although nobody else seems to be using it. I don't know, it's kind of depressing. :unsure: I wish there was a better way to learn about this.
     
  11. eva2000

    eva2000 Administrator Staff Member

    54,070
    12,176
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,734
    Local Time:
    2:44 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  12. BamaStangGuy

    BamaStangGuy Active Member

    668
    192
    43
    May 25, 2014
    Ratings:
    +272
    Local Time:
    10:44 AM
    How does this look after some time running?

    Code:
    pool:                 www
    process manager:      static
    start time:           02/Mar/2015:18:44:33 +0000
    start since:          77078
    accepted conn:        338417
    listen queue:         0
    max listen queue:     48
    listen queue len:     8150
    idle processes:       23
    active processes:     1
    total processes:      24
    max active processes: 24
    max children reached: 0
    slow requests:        0
    Linode 6 core server.
     
  13. deltahf

    deltahf Premium Member Premium Member

    585
    264
    63
    Jun 8, 2014
    Ratings:
    +486
    Local Time:
    11:44 AM
    After experiencing lots of issues with the Image Proxy after moving to SSL/SPDY, I have since had to change these values and abandon a static configuration. It's been running great since. For XenForo with the image proxy, I definitely recommend a dynamic value with a high max_children setting like what you're using, BamaStangGuy.

    My new settings and theory for why SPDY caused the problem are here: XF 1.4 - Image Proxy crashing PHP-FPM after moving to SSL | XenForo Community
     
  14. BamaStangGuy

    BamaStangGuy Active Member

    668
    192
    43
    May 25, 2014
    Ratings:
    +272
    Local Time:
    10:44 AM
    We use DigitalPoint's Image Proxy system and have no issue with using Static.
     
  15. BamaStangGuy

    BamaStangGuy Active Member

    668
    192
    43
    May 25, 2014
    Ratings:
    +272
    Local Time:
    10:44 AM
    @deltahf what are you currently using for your fpmconf with dynamic?
     
  16. deltahf

    deltahf Premium Member Premium Member

    585
    264
    63
    Jun 8, 2014
    Ratings:
    +486
    Local Time:
    11:44 AM
    Here's what I'm running on my new dedicated server (specs here):

    Code:
    pm = dynamic
    pm.max_children = 32
    pm.start_servers = 6
    pm.min_spare_servers = 6
    pm.max_spare_servers = 10
    pm.max_requests = 500
    It's been running great (no downtime caused by the image proxy that I can see), but I just noticed I'm getting a few of the these errors each day in /var/log/php-fpm/www-error.log so it's time to adjust some values...

    Code:
    [20-May-2015 14:41:55] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 15 total children
     
  17. BamaStangGuy

    BamaStangGuy Active Member

    668
    192
    43
    May 25, 2014
    Ratings:
    +272
    Local Time:
    10:44 AM
    We are hitting max pm servers at 128. Our new configuration looks like this:

    Code:
    pm = dynamic
    pm.max_children = 256
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 8
    pm.min_spare_servers = 8
    pm.max_spare_servers = 16
    pm.max_requests = 150
     
    Last edited: May 22, 2015
  18. jeffwidman

    jeffwidman Active Member

    152
    27
    28
    Dec 3, 2014
    Ratings:
    +51
    Local Time:
    8:44 AM
    Why set max requests so low? Respawning processes is an expensive operation compared to just reusing them a bit longer.
     
  19. BamaStangGuy

    BamaStangGuy Active Member

    668
    192
    43
    May 25, 2014
    Ratings:
    +272
    Local Time:
    10:44 AM
    We have it set to 250 currently.