How to fix MySQL high CPU usage
Majority web applications are database driven. MySQL is a popular database server for open source applications, but we’ve seen that it can cause performance issues in the long run.
MySQL databases grow in size, and tables get fragmented over time. This contributes to MySQL load spikes. So, protecting a server from MySQL high CPU issues requires close monitoring and periodic optimization.
In Bobcares’ Server Management services, there are 3 key operations that we do to keep MySQL server stable:
1. Initial server optimization
When we setup a server or during initial server optimization task in the servers manage, we perform custom tweaking of the MySQL server to tune them best for the customer’s business.
After analyzing the website types and traffic, we tweak the key settings in MySQL servers that helps to ensure optimal resource usage – such as the connection limits, buffer size and query cache size, etc.,
2. 24/7 monitoring & emergency rescue
A vulnerability in MySQL server is usually revealed when there’s a spike in server traffic. So, it is important to keep a close watch on the server metrics round the clock.
Our experts monitor MySQL health 24/7, which helps us to detect a spike in the CPU usage or abusive processes promptly and to fix them before it crashes the entire server.
3. Follow-up audit & optimization
While many server administrators handle high load with a service restart, those are just temporary fixes. If proper investigation and tweaking is not done, the load spike can happen again.
At Bobcares, we do a follow-up investigation to audit the MySQL settings to see WHY an issue happened in the first place, and then optimize the tables and tweak MySQL settings so that it won’t happen again.
Today, we’ll take a look at how we react to a MySQL high CPU situation, and what we do to prevent its recurrence.
[ You don’t have to be a MySQL expert to keep your sites fast and stable. Our server experts would help you to maintain your MySQL server stable. ]
How to detect MySQL high CPU usage
Very often people link high server load to high CPU usage. That is not always true. Server load can go high due to bottlenecks in any resource. This can include memory, disk I/O, network or CPU.
The top reason for MySQL induced server load is due to memory or I/O exhaustion. If it is CPU bottleneck, the output of top would look like this:
top - 8:31:15 up 23 days, 3:33, 1 user, load average: 22.31, 19.72, 25.02 Tasks: 81 total, 5 running, 76 sleeping, 0 stopped, 0 zombie Cpu(s): 87.8%us, 0.3%sy, 0.0%ni, 11.2%id, 0.0%wa, 0.2%hi, 0.5%si, 0.0%st Mem: 2975920k total, 1018219k used, 1957701k free, 287408k buffers
If it is I/O induced bottleneck, the %wa (called wait average) will have the highest CPU%. In contrast, if it is a memory induced load, the “free” memory would be limited to just a few MBs.