如何确定CPU瓶颈

本文涉及的产品
云数据库 RDS SQL Server,基础系列 2核4GB
RDS SQL Server Serverless,2-4RCU 50GB 3个月
推荐场景:
简介: Detect CPU Bottleneck in SQL Server By : Kasim Wirama, MCDBA   When you have your database server experiencing a problem, there are many possibilit...

Detect CPU Bottleneck in SQL Server

By : Kasim Wirama, MCDBA

 

When you have your database server experiencing a problem, there are many possibilities here, such as CPU, memory, hard disk or database configuration itself. There should be a systematic way to trouble shooting performance problem in SQL Server. This article, I would like to point out how to detect bottleneck in CPU with SQL Server 2005.

 

The straight forward way to detect CPU problem is to look at performance counter,  with object : Processor, and counter name : %Processor Time. If it shows high percentage value, let’s say 80% or over during 15 to 20 minutes, you definitely have CPU bottleneck. Anyway, you need to establish your baseline for CPU threshold above. Another counter name that is useful is System:Processor Queue Length. This counter gives information how long a queue for each processor. If you see 2 or more value for most of the time,  your processors are under pressure. When your server box has some applications running besides SQL Server, probably one of the application takes up significant CPU resource. To prove your suspicious thought, get information from Process:%Processor Time counter.

 

If you have your CPU bottleneck caused by SQL Server, you need to find out how many processes that are running, runnable, and suspended. An amount of runnable processes indicate that the CPU is busy serving other request, and an amount of suspended processes indicate that there is blocking issue. Here is the query to get the information.

 

SELECT COUNT(*) , t2.scheduler_id
From sys.dm_os_workers as t2, sys.dm_os_schedulers as t2
Where t1.state = ‘runnable/running/suspended’ and t1.scheduler_address = t2.scheduler_address and t2.scheduler_id < 255
Group by t2.scheduler_id

 

In general, there are 2 things that causes CPU bottleneck, they are :

 

  1. 1.       Inefficient query plan.

If you want to associate the query with CPU bottleneck, you query it from DMV sys.dm_exec_query_stats  and extract query text from sys.dm_exec_sql_text with parameter sql_handle. You sort the result based on most expensive average CPU cost that consists of division between total_worker_time and execution_count

 

  1. 2.       Excessive compilation and recompilation.

If SQL Server needs some time to compile/recompile the query, it shows that your execution plan is not reusable. If your query is very complex, try to rewrite/adding some index that will make the compilation time run faster.

These are 3 performance counter relating to excessive compilation/recompilation issue :

  1. a.       SQL SERVER: SQL Statistics : Batch Requests/Sec
  2. b.      SQL SERVER: SQL Statistics : SQL Compilations/Sec
  3. c.       SQL SERVER: SQL Statistics : SQL Recompilations /Sec

 

With wealth information from DMV and performance monitor, you have a useful tool for troubleshooting CPU bottleneck right away.

相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS&nbsp;SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/sqlserver
目录
相关文章
|
10天前
|
监控 负载均衡 算法
CPU占用率爆表:高效诊断与解决CPU 100%问题
在系统运维和软件开发中,CPU占用率达到100%是一个常见的性能瓶颈问题。这种情况可能会导致系统响应缓慢,甚至崩溃。本文将分享如何高效诊断和解决CPU占用率过高的问题,帮助你快速定位并解决问题。
30 5
|
20天前
|
存储 缓存
CPU性能
【10月更文挑战第30天】CPU性能
33 3
|
1月前
|
存储 缓存 算法
CPU优化
【10月更文挑战第7天】
31 1
|
1月前
|
存储 缓存 监控
如何提高服务器CPU性能?
如何提高服务器CPU性能?
153 3
|
Java 测试技术 BI
一文告诉你CPU分支预测对性能影响有多大
CPU分支预测本身是为了提升流水线下避免流水线等待的手段,其实本质上是利用了局部性原理,因为局部性的存在,大多数情况下这个技术本身给性能带来的是正向的(要不然它今天也不会存在了),所以我们大多数情况下都不需要关注它的存在,还是放心大胆的写代码吧,不要因为我们这篇博客就把所有的if改成?:三目运算,可能对代码可读性的影响远大于性能提升的收益。再次强调下,我今天只是构造了一个极端的数据来验证其性能差异,因为局部性的存在大多数情况下分支预测都是对的。
122 0
|
机器学习/深度学习 传感器 Linux
【操作系统】CPU平均负载和使用率
【操作系统】CPU平均负载和使用率
【操作系统】CPU平均负载和使用率
|
算法 调度
2.2.2操作系统(CPU利用率 系统吞吐量 周转时间 调度算法 FCFS SJF HRRN)
调度算法的评价指标 ​1.CPU利用率 2.系统吞吐量 3.周转时间 4.等待时间 5.响应时间 调度算法 1.先来先服务(FCFS, First Come First Serve) 2.短作业优先(SJF, Shortest Job First) 非抢占式 抢占式 ​注意几个小细节: 对FCFS和SJF两种算法的思考… 3.高响应比优先(HRRN, Highest Response Ratio Next) 知识回顾与重要考点
2.2.2操作系统(CPU利用率 系统吞吐量 周转时间 调度算法 FCFS SJF HRRN)
|
Java API
可能导致CPU占用率过高的场景与解决方案
尽量减少无限循环、让循环执行得慢一点(sleep)
|
监控 算法 Java
CPU扛不住了
这是一篇根据生活编撰的一个小故事,讲述了一个比较少见的服务器问题——CPU利用率过高。文中包含了从CPU过高告警,到一步步定位到导致CPU过高的代码的追溯过程。 前面是故事,最后面是定位的总结,根据需要酌情使用。 声明:故事很小,如有雷同,纯属虚构。