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

Wordpress 100% CPU usage - Need some help

Discussion in 'Blogs & CMS usage' started by coldice, Dec 13, 2017.

  1. coldice

    coldice Member

    35
    1
    8
    Nov 27, 2017
    India
    Ratings:
    +2
    Local Time:
    8:57 AM
    1.13.7
    10.1.29
    Hello,

    From the beginning, I am getting 100% CPU usage without any reason. When I run top it shows 2-3 php-fpm PIDs with 40,50,20% as cpu usage. On nixstats.com sometimes in process tab it shows more than 200% as CPU. I have tried to set children to 10,50,100 but still no luck. I have also disabled wordpress cron jobs from wp-config.
    If I buy 300-1000 visitors via pop in google analytics only 400-500 out of 1000 appears. But if I use link shortner and use my play store app link all them go through it.
    Even php-fpm starts using 100% of CPU for 300 users. I saw users able to get 10M visitors per day on 2GB RAM server with nginx + php-fpm + wordpres. But in my case its not happening.
    I also ran loader.io tests and 1000 clients per minute were delivered without any drop.
    5000 clients per minute were delivered with 2% of drop.

    Earlier I was having few problems & I have solved it by updating nginx & php.
    My current server config:
    Code:
    CPU: Intel E5 4-Core
    Ram: 12 GB
    SSD: 300 GB
    Provider: Contabo
    
    When I test for server response I get 70-85ms.

    Website info:
    Code:
    I have news website with average page size of 2MB.
    Redis server is running properly
    I am not using any plugin like wp super cache
    Only redis object cache + nginx helper is used
    Using PositiveSSL with HTTPS as default.
    domain.conf is disabled
    Currently, my site has 5k articles
    I can provide login to nixstats.com to check server stats.

    *I have to enable CRON jobs to start my work.
     
  2. pamamolf

    pamamolf Well-Known Member

    3,117
    295
    83
    May 31, 2014
    Ratings:
    +531
    Local Time:
    5:27 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    That means that the system and mysql and phpfpm and all the rest is using only one core as the 100% usage is for one core.

    If two cores are full you should see 200% and so on and for your server the maximum theoretical for the 4 cores is 400%.

    I think it will be better for you to change the default ondemand and use dynamic and try with children around 20-30.

    Per day is not the same with all users at the same time that you try!

    It will help a lot if you use KeyCDN Cache Enabler.....

    Also cloudflare in front can help a lot....
     
  3. eva2000

    eva2000 Administrator Staff Member

    36,877
    8,073
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,433
    Local Time:
    1:27 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    CPU load optimal is 1.0 per cpu thread so 8 cpu thread normal = 8x1 = 8.0. 16 cpu server normal is 16x1 = 16.0. So a 4 cpu thread VPS with 200% cpu load = 2/4 = 0.5 cpu load average.

    so cpu load of 8 for
    • 2 cpu server = 8/2 = 4.0 load average
    • 4 cpu server = 8/4 = 2.0 load average
    • 8 cpu server = 8/8 = 1.0 load average
    When you type top command, hit number 1 to break down per cpu stats

    Centmin Mod is provided as is, so troubleshooting load issues is left to end user to do. 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:
    For example what's output for these commands
    Code (Text):
    top -bn1
    

    Code (Text):
    ps aufxw
    

    Code (Text):
    sar -q
    

    Code (Text):
    sar -r
    

    Code (Text):
    sar -q -f /var/log/sa/sa$(date +%d -d yesterday)
    

    Code (Text):
    sar -r -f /var/log/sa/sa$(date +%d -d yesterday)
    

    for posting code you might want to use CODE tags for code How to use forum BBCODE code tags :)

    agreed wp caching is a must
     
  4. coldice

    coldice Member

    35
    1
    8
    Nov 27, 2017
    India
    Ratings:
    +2
    Local Time:
    8:57 AM
    1.13.7
    10.1.29
    Is redis not enough for caching?
     
  5. coldice

    coldice Member

    35
    1
    8
    Nov 27, 2017
    India
    Ratings:
    +2
    Local Time:
    8:57 AM
    1.13.7
    10.1.29
    I have attached the outputs of the commands you stated above:

    sar -r -f varlogsasa$(date +%d -d yesterday) · GitHub
    ps aufxw · GitHub
    sar -q -f varlogsasa$(date +%d -d yesterday) · GitHub
    sar -q · GitHub
    sar -r · GitHub
    top bn-1 · GitHub

    Output of top:
    Seems like all 4 cores are used by php-fpm
    [​IMG]
    [​IMG]

    /usr/local/etc/php-fpm.conf

    Code:
    [global]
    ; Log level
    ; Possible Values: alert, error, warning, notice, debug
    ; Default Value: notice
    log_level = warning
    pid = /var/run/php-fpm/php-fpm.pid
    error_log = /var/log/php-fpm/www-error.log
    emergency_restart_threshold = 10
    emergency_restart_interval = 1m
    process_control_timeout = 10s
    ;include=/usr/local/nginx/conf/phpfpmd/*.conf
    
    [www]
    user = nginx
    group = nginx
    
    listen = 127.0.0.1:9000
    listen.allowed_clients = 127.0.0.1
    ;listen.backlog = -1
    
    ;listen = /tmp/php5-fpm.sock
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0660
    
    pm = ondemand
    pm.max_children = 120
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 25
    pm.min_spare_servers = 25
    pm.max_spare_servers = 35
    pm.max_requests = 500
    pm.status_path = /status_phpfpm
    
    ; PHP 5.3.9 setting
    ; The number of seconds after which an idle process will be killed.
    ; Note: Used only when pm is set to 'ondemand'
    ; Default Value: 10s
    pm.process_idle_timeout = 10s;
    
    rlimit_files = 131072
    rlimit_core = unlimited
    
    ; The timeout for serving a single request after which the worker process will
    ; be killed. This option should be used when the 'max_execution_time' ini option
    ; does not stop script execution for some reason. A value of '0' means 'off'.
    ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
    ; Default Value: 0
    ;request_terminate_timeout = 60
    ; Default Value: 0
    ;request_slowlog_timeout = 0
    slowlog = /var/log/php-fpm/www-slow.log
    
    pm.status_path = /phpstatus
    ping.path = /phpping
    ping.response = pong
    
    ; Limits the extensions of the main script FPM will allow to parse. This can
    ; prevent configuration mistakes on the web server side. You should only limit
    ; FPM to .php extensions to prevent malicious users to use other extensions to
    ; exectute php code.
    ; Note: set an empty value to allow all extensions.
    ; Default Value: .php
    security.limit_extensions = .php .php3 .php4 .php5
    
    ; catch_workers_output = yes
    php_admin_value[error_log] = /var/log/php-fpm/www-php.error.log
    php_admin_value[disable_functions] = shell_exec
    
    
     
    Last edited: Dec 13, 2017
  6. eva2000

    eva2000 Administrator Staff Member

    36,877
    8,073
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,433
    Local Time:
    1:27 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    looks entirely normal there cpu load for 1 min interval is 2.24 so load average is 2.24/4 = 0.56 cpu load average or 56% cpu utilisation.
     
  7. eva2000

    eva2000 Administrator Staff Member

    36,877
    8,073
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,433
    Local Time:
    1:27 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    you selected redis nginx level caching from centmin.sh menu option 22 wordpress installer ? if so yes that is enough. But if you didn't and just installed redis server, then that is not enough as redis needs to be configured at both nginx and wordpress plugin level (which centmin.sh menu option 22 installer automatically does)
     
  8. coldice

    coldice Member

    35
    1
    8
    Nov 27, 2017
    India
    Ratings:
    +2
    Local Time:
    8:57 AM
    1.13.7
    10.1.29
    [​IMG]
    Imgur: The magic of the Internet

    Here's my Redmon stat. I think redis is working perfectly with wordpress.
    I have around 5k+ article.
    Should set redis TTL to an higher value?
     
  9. eva2000

    eva2000 Administrator Staff Member

    36,877
    8,073
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,433
    Local Time:
    1:27 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    probably need to raise your redis memory cache allocation from ~100MB to something higher
     
  10. coldice

    coldice Member

    35
    1
    8
    Nov 27, 2017
    India
    Ratings:
    +2
    Local Time:
    8:57 AM
    1.13.7
    10.1.29
    Where can I specify the redis memory?

    My average page size is 2MB, Do you think brotli compression will increase my performance?
    My current ping dom stat:
    [​IMG]

    Is this normal to have 100%+ php-fpm usage?
    [​IMG]
     
  11. eva2000

    eva2000 Administrator Staff Member

    36,877
    8,073
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,433
    Local Time:
    1:27 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    if you followed guide at Redis - How to install Redis server on Centmin Mod LEMP stack to setup redis as LRU cache, then you would of set memory allocation to 100MB in redis config at /etc/redis.conf
    Code (Text):
    maxmemory 100mb
    

    yes normal for php-fpm to be cpu intensive if you have php heavy traffic sites
     
  12. eva2000

    eva2000 Administrator Staff Member

    36,877
    8,073
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,433
    Local Time:
    1:27 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    FYI, redis object cache isn't same as centmin.sh menu option 22 wordpress installer's redis nginx level caching which is better for handling load
     
  13. coldice

    coldice Member

    35
    1
    8
    Nov 27, 2017
    India
    Ratings:
    +2
    Local Time:
    8:57 AM
    1.13.7
    10.1.29
    I think I have messed up with my WP installation.
    I did installed via option 22 + redis without SSL but after that I installed SSL.

    Then you helped me in setting up SSL on this thread: Wordpress - ERR_Connection_Refused 10 out of 100 times.

    On running
    curl -s https://domain.com/136687/ | tail -3
    Code:
    <!--Cached using Nginx-Helper on 2017-12-13 15:11:33. It took 5 queries executed in 0.211 seconds.-->
    <!--Visit Nginx Helper for more details-->
     
  14. coldice

    coldice Member

    35
    1
    8
    Nov 27, 2017
    India
    Ratings:
    +2
    Local Time:
    8:57 AM
    1.13.7
    10.1.29
    Will brotli compression increase my wordpress page delivery speed?
     
  15. eva2000

    eva2000 Administrator Staff Member

    36,877
    8,073
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,433
    Local Time:
    1:27 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    that actually looks correct.. look in redis admin for full page cached entries to confirm
    yes but at cost of maybe a slight bit more cpu usage for the benefit

    your cpu load from stats provided is fine though 2.2 cpu load = 2.2/4 cpu threads = 0.55 cpu load average = 55% cpu utilisation which is well within range of being comfortable.
     
    • Like Like x 1
  16. coldice

    coldice Member

    35
    1
    8
    Nov 27, 2017
    India
    Ratings:
    +2
    Local Time:
    8:57 AM
    1.13.7
    10.1.29
    @eva2000 I buy traffic for my site but out of 1000 only 400-500 are delivered. Is there any way I can check why it's happening?
     
  17. eva2000

    eva2000 Administrator Staff Member

    36,877
    8,073
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,433
    Local Time:
    1:27 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    You can try checking the domain site's vhost access.log and error.log logs located within directory at /home/nginx/domains/yourdomain.com/logs for clues. You can see a full overview at centminmod.com/configfiles.html

    FAQ item 19 has more info on all Centmin Mod relevant log files locations and how to use tail command to view a sample of the entries.
     
  18. coldice

    coldice Member

    35
    1
    8
    Nov 27, 2017
    India
    Ratings:
    +2
    Local Time:
    8:57 AM
    1.13.7
    10.1.29
    @eva2000
    Can I use nginx FastCGI cache just by switching with nginx helper plugin just by removing redis object cache plugin and selecting nginx Fastcgi cache? Will it work or there's something I need to change in vhost file?
     
  19. eva2000

    eva2000 Administrator Staff Member

    36,877
    8,073
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,433
    Local Time:
    1:27 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Yeah should work but need to edit vhost too
     
  20. coldice

    coldice Member

    35
    1
    8
    Nov 27, 2017
    India
    Ratings:
    +2
    Local Time:
    8:57 AM
    1.13.7
    10.1.29
    I just got another issue. Redis is caching my admin panel also. I tried to disable a plugin but when I click on deactivate it says plugin deactivated but when I check plugin status is still activated. Then I disabled redis object cache and nginx helper then I was able to deactivate the plugin.

    My also has theme panel and was not able to change those options because redis cached all those.
    Is it possible that redis doing it?
     
..