Question

CPU usage problem by MySQL In a WordPress site

I have a wordpress site on digital ocean with following configuration ubuntu 18 OS, php7.2-fpm, mariadb, wordpress

they are hosted on a 80$ droplet, A 4 core dedicated cpu droplet still my site goes DOWN, on checking graphs everything is normal i.e CPU usage is 20%, Disk at 50%, Memory at 33% but still site gives a 502 error during high traffic.

when i SSH into droplet and use Ubuntu’s command htop i see a single mysql pid using upto 200% CPU, is this a reporting problem ?

why all 4 core of my CPU is around 20-40% but a single pid of mysql is using 200% CPU internally and crashing the site and how can i fix it ?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Guessing you’re using the default Wordpress Droplet “out of the box”? If so, you likely need to do some tuning as I recall it is not configured to run production.

Really truly need more information about what plugins you’re running with Wordpress as well and what kind of site it is. Running Woocommerce with a healthy dose of supporting plugins can really put load on things compared to a blog with many more concurrent users.

Without much information the first thing I would do is split the web server out from the database and possibly switch to Nginx, or if you’re running woo or some heavy php utilization app then apache with nginx as reverse proxy.

Then Install MySQLTuner if you’re still seeing the same issue if you’re looking for more help. It will take you another step.

Finally, I love NewRelic for application tuning!

Honestly you would be better off not building from scratch, but instead using a container configuration tuned and configured by people who’ve already done the hard work of performance tuning and configuration management. They’ve made the mistakes for you and fixed them. You’re just kind of starting from scratch. You can do that and use a basic plugin to migrate to a new set of containers.

There is no one thing that you can show that will fix your issue. Troubleshooting performance is a process of first validating configuration. You’ve built your own from scratch so that will be a complicated step by step process only you can undertake.

Once you’ve validated you don’t have any basic configuration mistakes nor any basic tuning for the volume you’re seeing, then you turn to basic performance tuning: you always go after the biggest bottleneck and work through each one until you’re satisfied.

For you, that is CPU (I’m not convinced you’re looking properly at I/O nor at Memory. Based on the way you are giving %s for each you’re looking at monitoring that is used for capacity management, not problem or performance management. htop is a start, you should also be concurrently looking at iostat, mysqltuner, maybe even give Nagios a go, but that will take you time you likely don’t have. Percona does consulting, and there are wordpress tuning experts, but that will cost you a fortune or get you nowhere cheaply.

The short of it: there’s no easy answer here if you really believe your tech stack is properly configured. You have to do the hard work of troubleshooting and monitoring specifically during your problem periods at a much tighter interval (seconds instead of minutes).

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel