CPU Usage Increase
If the CPU usage of an RDS for MySQL instance increases or reaches 100%, the database response may become slow and new connections may time out.
Scenario 1: CPU Usage Increase Caused by Slow Queries
Cause: Too many slow SQL queries increase CPU usage. The slow SQL queries need to be optimized.
Troubleshooting
View the CPU usage and slow query logs.
- If a large number of slow query logs are generated and the change is consistent with the CPU usage curve, you know it is the slow SQL queries that are increasing the CPU usage.
- If there are not very many slow query logs but the change is basically consistent with the CPU usage curve, check whether the row read rate change is consistent with the CPU curve.
If yes, the CPU usage increase is caused by access to a large amount of row data. Although there are a small number of slow SQL queries, the queries need to access a large amount of row data, causing high average I/O. Therefore, even if the QPS is not high (for example, the website access traffic is not heavy), the CPU usage of the instance is also high.
Solution:
- View slow query logs generated within the corresponding time period.
- Note any slow queries with more than a million rows scanned or more than a million rows returned, and slow queries with long lock waiting time.
- Analyze slow queries or use SQL Diagnosis.
- Create read replicas and enable Database Proxy to split read and write requests. Read replicas can offload the read pressure from the primary instance, thus improving the database throughput. For details, see Introducing Read/Write Splitting.
- Analyze live sessions on the database to locate slow SQL statements.
- Connect to the database.
- Run the show full processlist; command.
- Analyze sessions that take a long time to execute and are in the Sending data, Copying to tmp table, Copying to tmp table on disk, Sorting result, or Using filesort state.
Scenario 2: CPU Usage Increase Caused by Increased Connections and QPS
Cause: Too many requests
Troubleshooting:
Check whether the changes of the QPS, active connections, total connections, and CPU usage are consistent.
QPS refers to the number of queries per second. If the QPS and active connections increase at the same time, and the QPS curve matches the CPU usage curve, the CPU usage increase is caused by increased requests, as shown in the following figure.
In this scenario, SQL statements are usually simple and the execution efficiency is high. There is little room for optimization on SQL statements. You need to optimize the database.
Solution:
- Upgrade the vCPU specifications of your instance because this problem usually occurs in instances with vCPU specifications such as 1 vCPU, 2 vCPUs, and 4 vCPUs.
- Optimize slow queries by referring to Scenario 1: CPU Usage Increase Caused by Slow Queries. If this method is not so helpful, upgrade the vCPU specifications of your instance.
- Use database and table sharding for tables with a large amount of data to reduce the amount of data accessed in a single query.
- Create read replicas and enable Database Proxy to split read and write requests. Read replicas can offload the read pressure from the primary instance, thus improving the database throughput. For details, see Introducing Read/Write Splitting.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot