Skip to content

Commit 4cee501

Browse files
authored
Merge pull request #117378 from moabuham/patch-5
Update how-to-troubleshoot-high-cpu-utilization.md
2 parents 5bc8ecd + 15ad07b commit 4cee501

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

articles/mysql/single-server/how-to-troubleshoot-high-cpu-utilization.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,32 @@ For example, consider a sudden surge in connections that initiates surge of data
2121

2222
Besides capturing metrics, it’s important to also trace the workload to understand if one or more queries are causing the spike in CPU utilization.
2323

24+
## High CPU causes
25+
26+
CPU spikes can occur for various reasons, primarily due to spikes in connections and poorly written SQL queries, or a combination of both:
27+
28+
#### Spike in connections
29+
30+
An increase in connections can lead to an increase in threads, which in turn can cause a rise in CPU usage as it has to manage these connections along with their queries and resources. To troubleshoot a spike in connections, you should check the [Total Connections](./../flexible-server/concepts-monitoring.md#list-of-metrics) metric and refer to the next section for more details about these connections. You can utilize the performance_schema to identify the hosts and users currently connected to the server with the following commands:
31+
32+
Current connected hosts
33+
```
34+
select HOST,CURRENT_CONNECTIONS From performance_schema.hosts
35+
where CURRENT_CONNECTIONS > 0
36+
and host not in ('NULL','localhost');
37+
```
38+
39+
Current connected users
40+
```
41+
select USER,CURRENT_CONNECTIONS from performance_schema.users
42+
where CURRENT_CONNECTIONS >0
43+
and USER not in ('NULL','azure_superuser');
44+
```
45+
46+
#### Poorly written SQL queries
47+
48+
Queries that are expensive to execute and scan a large number of rows without an index, or those that perform temporary sorts along with other inefficient plans, can lead to CPU spikes. While some queries may execute quickly in a single session, they can cause CPU spikes when run in multiple sessions. Therefore, it’s crucial to always explain your queries that you capture from the [show processlist](https://dev.mysql.com/doc/refman/5.7/en/show-processlist.html) and ensure their execution plans are efficient. This can be achieved by ensuring they scan a minimal number of rows by using filters/where clause, utilize indexes and avoid using large temporary sort along with other bad execution plans. For more information about execution plans, see [EXPLAIN Output Format](https://dev.mysql.com/doc/refman/5.7/en/explain-output.html).
49+
2450
## Capturing details of the current workload
2551

2652
The SHOW (FULL) PROCESSLIST command displays a list of all user sessions currently connected to the Azure Database for MySQL server. It also provides details about the current state and activity of each session.

0 commit comments

Comments
 (0)