Join the community today
Register Now

Nginx PHP-FPM Php-fpm optimization

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Manoj malviya, Jan 18, 2020.

  1. Manoj malviya

    Manoj malviya New Member

    19
    1
    3
    Dec 21, 2019
    Ratings:
    +1
    Local Time:
    8:12 PM
    1.17.6
    10.3.20
    i have a dedicated server which have 128 gb of ram and xeon processor with 1gbps bandwidth. I have installed centminmod on my server but the issue I am facing is that when my traffic raise to 3000 realtime the server stop responding.

    What I am looking for what will be the configuration of php-fpm so it can handle 10000 realtime users
     
  2. eva2000

    eva2000 Administrator Staff Member

    45,405
    10,302
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,980
    Local Time:
    12:42 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    Start with reading how to read and monitor your PHP-FPM stats/status at https://community.centminmod.com/threads/how-to-troubleshoot-optimize-php-fpm-server.15317/

    Output from cminfo sar-cpu, sar-mem, phpstats command would help
    Code (Text):
    cminfo sar-cpu
    

    Code (Text):
    cminfo sar-mem
    

    Code (Text):
    cminfo phpstats
    

    php configuration output
    Code (Text):
    php-config

    For posting code or output from commands to keep the formatting, you might want to use CODE tags for code How to use forum BBCODE code tags :)
     
  3. Manoj malviya

    Manoj malviya New Member

    19
    1
    3
    Dec 21, 2019
    Ratings:
    +1
    Local Time:
    8:12 PM
    1.17.6
    10.3.20
    I just want to know according my server configuration what will be the pm_maxchildren configuration for 128 gb of ram should i configure it to static or dynamic.
     
  4. eva2000

    eva2000 Administrator Staff Member

    45,405
    10,302
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,980
    Local Time:
    12:42 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
  5. rdan

    rdan Well-Known Member

    4,987
    1,186
    113
    May 25, 2014
    Ratings:
    +1,808
    Local Time:
    10:42 PM
    Mainline
    10.2
    Try this config:
    Code:
    pm = dynamic
    pm.max_children = 64
    pm.start_servers = 32
    pm.min_spare_servers = 16
    pm.max_spare_servers = 48
    pm.max_requests = 5000
    
     
  6. Manoj malviya

    Manoj malviya New Member

    19
    1
    3
    Dec 21, 2019
    Ratings:
    +1
    Local Time:
    8:12 PM
    1.17.6
    10.3.20
    How you calculate this will it able to handle 10000 realtime users?
     
  7. rdan

    rdan Well-Known Member

    4,987
    1,186
    113
    May 25, 2014
    Ratings:
    +1,808
    Local Time:
    10:42 PM
    Mainline
    10.2
    Try and see first.
    Just my own config calculation.
    Code:
    pm = dynamic
    pm.max_children = cpu x 4
    pm.start_servers = cpu x 2
    pm.min_spare_servers = # of cpu
    pm.max_spare_servers = cpu x 3
    pm.max_requests = 5000
     
  8. rdan

    rdan Well-Known Member

    4,987
    1,186
    113
    May 25, 2014
    Ratings:
    +1,808
    Local Time:
    10:42 PM
    Mainline
    10.2
    Implement it first then observe for few hours or a day.
     
  9. Manoj malviya

    Manoj malviya New Member

    19
    1
    3
    Dec 21, 2019
    Ratings:
    +1
    Local Time:
    8:12 PM
    1.17.6
    10.3.20
    ok I will check and let you know once i have got that much traffic on my website at my time zone.
     
  10. Manoj malviya

    Manoj malviya New Member

    19
    1
    3
    Dec 21, 2019
    Ratings:
    +1
    Local Time:
    8:12 PM
    1.17.6
    10.3.20

    Will it depend on ram of the server because on all other forum people talking about ram.
     
  11. rdan

    rdan Well-Known Member

    4,987
    1,186
    113
    May 25, 2014
    Ratings:
    +1,808
    Local Time:
    10:42 PM
    Mainline
    10.2
    Based on my experienced, doesn't much as PHP is CPU hungry not much on the Memory.
    Your CPU will suffer much than RAM with high traffic.

    I have a 32GB RAM Server that can handle 10K GA Real-time user's very fine, though request are 98% cache via wp super cache.
     
  12. Manoj malviya

    Manoj malviya New Member

    19
    1
    3
    Dec 21, 2019
    Ratings:
    +1
    Local Time:
    8:12 PM
    1.17.6
    10.3.20
    Some one recommend this configuration
    You can try something like:

    pm = dynamic
    pm.max_children = 80
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 32
    pm.min_spare_servers = 16
    pm.max_spare_servers = 64
    pm.max_requests = 8000

    By using this command

    ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"Mb") }'

    Output:- 46MB

    Currenctly have 250 users on my website which is coded in codeigniter.
     
  13. eva2000

    eva2000 Administrator Staff Member

    45,405
    10,302
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,980
    Local Time:
    12:42 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    see

     
  14. Manoj malviya

    Manoj malviya New Member

    19
    1
    3
    Dec 21, 2019
    Ratings:
    +1
    Local Time:
    8:12 PM
    1.17.6
    10.3.20
    1700 users got this issue
    [18-Jan-2020 15:10:47] WARNING: [pool www] server reached pm.max_children setting (80), consider raising it
     
  15. rdan

    rdan Well-Known Member

    4,987
    1,186
    113
    May 25, 2014
    Ratings:
    +1,808
    Local Time:
    10:42 PM
    Mainline
    10.2
    Try and add this at the bottom of php-fpm.conf
     
  16. pamamolf

    pamamolf Premium Member Premium Member

    3,857
    378
    83
    May 31, 2014
    Ratings:
    +729
    Local Time:
    5:42 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    One factor will be that mysql may not be well optimized and cause a delay to php and php keep opening new childs and reach the max related value....

    There are a ton of things to check....
     
  17. Manoj malviya

    Manoj malviya New Member

    19
    1
    3
    Dec 21, 2019
    Ratings:
    +1
    Local Time:
    8:12 PM
    1.17.6
    10.3.20
    I am not using MySQL its completely static website
     
  18. pamamolf

    pamamolf Premium Member Premium Member

    3,857
    378
    83
    May 31, 2014
    Ratings:
    +729
    Local Time:
    5:42 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    Then it will be better to wait for a recommandation from someone with more knowledge than me...
     
  19. rdan

    rdan Well-Known Member

    4,987
    1,186
    113
    May 25, 2014
    Ratings:
    +1,808
    Local Time:
    10:42 PM
    Mainline
    10.2
    and also create a file: /etc/centminmod/php.d/zzz_custom_php.ini
    With content:
    Since that is just a static Site with no database, you can try lowering it down to:
     
  20. rdan

    rdan Well-Known Member

    4,987
    1,186
    113
    May 25, 2014
    Ratings:
    +1,808
    Local Time:
    10:42 PM
    Mainline
    10.2
    Since only Nginx and PHP is working to serve your Site
    Try and apply this config:
    https://community.centminmod.com/threads/php-fpm-optimization.19034/#post-81010
    php-fpm.conf
    Code:
    pm = dynamic
    pm.max_children = 64
    pm.start_servers = 32
    pm.min_spare_servers = 16
    pm.max_spare_servers = 48
    pm.max_requests = 5000
    
    https://community.centminmod.com/threads/php-fpm-optimization.19034/#post-81027
    at the bottom of php-fpm.conf
    Code:
    request_terminate_timeout = 20s
    php_admin_value[disable_functions] = shell_exec
    php_admin_value[memory_limit] = 2048M
    
    https://community.centminmod.com/threads/php-fpm-optimization.19034/#post-81031
    /etc/centminmod/php.d/zzz_custom_php.ini
    Code:
    max_execution_time = 20
    memory_limit = 2048M
    opcache.memory_consumption=2048
    opcache.revalidate_freq=60
    
    Observe for few hours, I have more to suggest if it doesn't help much.