博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL技术内幕-13 SQL优化方法论之分离重量级的等待
阅读量:5087 次
发布时间:2019-06-13

本文共 2218 字,大约阅读时间需要 7 分钟。

Code

-- Isolate top waitsWITH Waits AS(  SELECT    wait_type,    wait_time_ms / 1000. AS wait_time_s,    100. * wait_time_ms / SUM(wait_time_ms) OVER() AS pct,    ROW_NUMBER() OVER(ORDER BY wait_time_ms DESC) AS rn,    100. * signal_wait_time_ms / wait_time_ms as signal_pct  FROM sys.dm_os_wait_stats  WHERE wait_time_ms > 0    AND wait_type NOT LIKE N'%SLEEP%'    AND wait_type NOT LIKE N'%IDLE%'    AND wait_type NOT LIKE N'%QUEUE%'        AND wait_type NOT IN(  N'CLR_AUTO_EVENT'                         , N'REQUEST_FOR_DEADLOCK_SEARCH'                         , N'SQLTRACE_BUFFER_FLUSH'                         /* filter out additional irrelevant waits */ ))SELECT  W1.wait_type,   CAST(W1.wait_time_s AS NUMERIC(12, 2)) AS wait_time_s,  CAST(W1.pct AS NUMERIC(5, 2)) AS pct,  CAST(SUM(W2.pct) AS NUMERIC(5, 2)) AS running_pct,  CAST(W1.signal_pct AS NUMERIC(5, 2)) AS signal_pctFROM Waits AS W1  JOIN Waits AS W2    ON W2.rn <= W1.rnGROUP BY W1.rn, W1.wait_type, W1.wait_time_s, W1.pct, W1.signal_pctHAVING SUM(W2.pct) - W1.pct < 80 -- percentage threshold    OR W1.rn <= 5ORDER BY W1.rn;GO
View Code

 1.从系统最后一次重启或计数器清空,该等待类型的总等待时间(以秒为单位)

2.该类型的等待时间占等待时间的百分比

3.从最重量级的等待类型到当前等待类型的连续百分比。

4.信号等待时间占等待时间的百分比,、(记住,wait_time_ms包含signal_wait_time_ms)

收集等待信息

-- Create the WaitStats tableUSE Performance;IF OBJECT_ID('dbo.WaitStats', 'U') IS NOT NULL DROP TABLE dbo.WaitStats;CREATE TABLE dbo.WaitStats(  dt                  DATETIME     NOT NULL DEFAULT (CURRENT_TIMESTAMP),  wait_type           NVARCHAR(60) NOT NULL,  waiting_tasks_count BIGINT       NOT NULL,  wait_time_ms        BIGINT       NOT NULL,  max_wait_time_ms    BIGINT       NOT NULL,  signal_wait_time_ms BIGINT       NOT NULL);CREATE UNIQUE CLUSTERED INDEX idx_dt_type ON dbo.WaitStats(dt, wait_type);CREATE INDEX idx_type_dt ON dbo.WaitStats(wait_type, dt);-- Load waitstats data on regular intervalsINSERT INTO Performance.dbo.WaitStats    (wait_type, waiting_tasks_count, wait_time_ms,     max_wait_time_ms, signal_wait_time_ms)  SELECT    wait_type, waiting_tasks_count, wait_time_ms,    max_wait_time_ms, signal_wait_time_ms  FROM sys.dm_os_wait_stats  WHERE wait_type NOT IN (N'MISCELLANEOUS');

 

转载于:https://www.cnblogs.com/alphafly/p/4395679.html

你可能感兴趣的文章
java编写提升性能的代码
查看>>
list 容器 排序函数.xml
查看>>
《Genesis-3D开源游戏引擎完整实例教程-跑酷游戏篇03:暂停游戏》
查看>>
CPU,寄存器,一缓二缓.... RAM ROM 外部存储器等简介
查看>>
git .gitignore 文件不起作用
查看>>
Alan Turing的纪录片观后感
查看>>
c#自定义控件中的事件处理
查看>>
IOS--沙盒机制
查看>>
使用 JointCode.Shuttle 访问任意 AppDomain 的服务
查看>>
sqlite的坑
查看>>
digitalocean --- How To Install Apache Tomcat 8 on Ubuntu 16.04
查看>>
【题解】[P4178 Tree]
查看>>
Mongo自动备份
查看>>
cer证书签名验证
查看>>
synchronized
查看>>
【深度学习】caffe 中的一些参数介绍
查看>>
Python-Web框架的本质
查看>>
QML学习笔记之一
查看>>
App右上角数字
查看>>
从.NET中委托写法的演变谈开去(上):委托与匿名方法
查看>>