How Can I Troubleshoot and Resolve High Cpu Utilization On My Amazon Rds For Mysql, Mariadb, or Aurora For Mysql Instances?
How Can I Troubleshoot and Resolve High Cpu Utilization On My Amazon Rds For Mysql, Mariadb, or Aurora For Mysql Instances?
Short Description
Several factors can cause an increase in CPU utilization. For example, user-initiated heavy
workloads, analytic queries, prolonged deadlocks and lock waits, multiple concurrent transactions,
long-running transactions, or other processes that utilize CPU resources.
First, you can identify the source of the CPU usage by:
Resolution
Using Enhanced Monitoring
Enhanced Monitoring provides granular real-time metrics that you can review in addition to Amazon
CloudWatch metrics, which provide statistics each minute. For more information, see the Differences
Between CloudWatch and Enhanced Monitoring Metrics.
In the operating system (OS) process list section of Enhanced Monitoring, review the OS
processes and RDS processes to confirm the percentage of CPU utilization of a mysqld or Aurora
process. These metrics can help you confirm if the increase in CPU utilization is caused by OS or
RDS processes. You can also use these metrics to confirm if the increase is caused by the mysqld
or Aurora, which can indicate that a user-initiated workload is the source of the CPU usage. For
more information, see Viewing Enhanced Monitoring. You can also see the bifurcation of CPU
utilization by reviewing the metrics for cpuUtilization. For more information, see the Available OS
Metrics.
You can also check the number of tasks that aren't in use (sleeping tasks). These tasks can lead to
increased memory resource (RAM, cache, and processor) consumption, which can slow down the
server. It's a best practice to tune your application to gracefully close the connections that aren't in
use. You can also modify the values for the wait_timeout and interactive_timeout parameters to
close the connection based on the value you set. For more information, see the MySQL
Documentation for wait_timeout and interactive_timeout.
Using Performance Insights
You can use Performance Insights to identify the exact queries that are running on the instance and
causing high CPU usage. First, enable Performance Insights for MySQL. Then, you can use
Performance Insights to optimize your workload after consulting with your DBA.
To see which database engines are available to use with Performance Insights, see Using Amazon
RDS Performance Insights.
Before you can optimize your workload, you must identify the problematic query. You can run the
following queries while the high CPU issue is occurring to identify the root cause of the CPU
utilization. Then, you can optimize your workload to reduce your CPU usage.
The SHOW PROCESSLIST command shows you which threads are running currently on your
MySQL instance. Sometimes, the same set of statements is running but not finishing. When this
happens, the subsequent statements must wait for the first set of statements to finish, because
InnoDB row-level locking might be updating the same rows. For more information, see the MySQL
Documentation for SHOW PROCESSLIST Syntax.
Note: Run the SHOW PROCESSLIST query as the master user. If you are not the master user, the
MySQL user running the command must have MySQL PROCESS server administration privileges to
see all the threads running on a MySQL instance. Without admin privileges, SHOW PROCESSLIST
shows only the threads associated with the MySQL account that you're using.