如何确定CPU瓶颈

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
简介:

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.





    本文转自 Fanr_Zh 博客园博客,原文链接:http://www.cnblogs.com/Amaranthus/archive/2011/03/28/1997684.html,如需转载请自行联系原作者



相关实践学习
使用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
相关文章
|
5月前
|
Java 测试技术 BI
一文告诉你CPU分支预测对性能影响有多大
CPU分支预测本身是为了提升流水线下避免流水线等待的手段,其实本质上是利用了局部性原理,因为局部性的存在,大多数情况下这个技术本身给性能带来的是正向的(要不然它今天也不会存在了),所以我们大多数情况下都不需要关注它的存在,还是放心大胆的写代码吧,不要因为我们这篇博客就把所有的if改成?:三目运算,可能对代码可读性的影响远大于性能提升的收益。再次强调下,我今天只是构造了一个极端的数据来验证其性能差异,因为局部性的存在大多数情况下分支预测都是对的。
57 0
|
9月前
|
监控 Shell Perl
监控CPU、内存和硬盘利用率
监控CPU、内存和硬盘利用率
109 1
|
11月前
|
机器学习/深度学习 传感器 Linux
【操作系统】CPU平均负载和使用率
【操作系统】CPU平均负载和使用率
【操作系统】CPU平均负载和使用率
|
Java API
可能导致CPU占用率过高的场景与解决方案
尽量减少无限循环、让循环执行得慢一点(sleep)
|
监控 算法 Java
CPU扛不住了
这是一篇根据生活编撰的一个小故事,讲述了一个比较少见的服务器问题——CPU利用率过高。文中包含了从CPU过高告警,到一步步定位到导致CPU过高的代码的追溯过程。 前面是故事,最后面是定位的总结,根据需要酌情使用。 声明:故事很小,如有雷同,纯属虚构。
|
数据挖掘 Shell 测试技术
App性能优化——内存、CPU、耗电、启动时间指标获取分析
考虑到既然是优化性能,那首先要获取App的相关性能指标,比如: 内存占用、CPU利用率、App启动时间、App耗电量等情况,获取以上各指标后,才能针对性分析确定是否存在优化的可能。
876 0
App性能优化——内存、CPU、耗电、启动时间指标获取分析
|
Linux Shell
一个限制进程 CPU 使用率的解决方案
一个限制进程 CPU 使用率的解决方案 一 背景 在最近的一个项目中,需要限制 CPU 使用率。通过查阅各种资料,发现已经有直接可以使用的软件可以使用,这个软件就是cpulimit,这个软件使用非常简单。
1429 0
|
网络协议 网络架构