一,使用 Performance counter 监控Disk IO问题

1,Physical Disk vs. Logical Disk

Windows可以在一个Physical Disk上划出若干个逻辑分区,每一个逻辑分区是一个Logical Disk。对于分配在同一个Physical Disk上的Logical Disks,其读写操作共享Physical Disk的IO带宽。Windows给每一个Logical Disk分配一个盘符,App通过盘符来读写数据。

关于Disk Performance,有两组counter:Logical Disk 和 Physical Disk。Logical Disk Counter按照逻辑分区记录每个逻辑分区的读写IO信息,由于App通过盘符来读写数据,通过logical Disk Counter可以了解不同App向不同盘符发出的读写请求有多少。Physical Disk Counter是按照物理磁盘,记录每一个物理磁盘的读写IO,能够了解disk的响应速度。如果Physical Disk上划分多个Logical Disk,那么这些Logical Partition将作为一个整体统计。

The Physical Disk performance object monitors disk drives on the computer. It identifies the instances representing the physical hardware, and the counters are the sum of the access to all partitions on the physical instance.      
The Logical Disk Performance object monitors logical partitions. Performance monitor identifies logical disks by their drive letter or mount point. If a physical disk contains multiple partitions, this counter will report the values just for the partition selected and not for the entire disk. On the other hand, when using Dynamic Disks the logical volumes may span more than one physical disk, in this scenario the counter values will include the access to the logical disk in all the physical disks it spans.

2, Disk Counter Explained

2.1 Disk Queue Length 是等待被Physical Disk处理的IO请求的数目。如果一个App发出一条读请求,但是目标Disk正在处理其他IO Task,那么这个新的请求就会被放在Disk queue中,Disk queue Length就是1.

Avg. Disk Queue Length ,Avg.Disk Read Queue Length,Avg.Disk Wirte Queue Length, Current Disk Queue length

2.2 Transfer 是Disk 的一次完整的I/O动作,表示从寻道,读写数据,到传输完成。在统计时,Transfer 是 Read 和 Write的加和。

Avg. Disk sec/Transfer : 磁盘每一次读写所用的平均时间。

Disk Transfers/sec : 磁盘每秒处理的读写次数。

Avg.Disk Bytes/Transfer:Disk 每次IO传送的Bytes数

2.3 Time percentage :Disk 处理IO请求和 elapsed time 的比值。

% Disk Time is the percentage of elapsed time that the selected disk drive was busy servicing write or read requests.

%Disk Time,% Disk Read Time,%Disk Write Time,%Idle Time

2.4 IO Split,一次IO拆分成多次IO来实现

Measures the rate of IO split due to file fragmentation. This happens if the IO request touches data on non-contiguous file segments.

Split IO/Sec reports the rate at which I/Os to the disk were split into multiple I/Os. A split I/O may result from requesting data of a size that is too large to fit into a single I/O or that the disk is fragmented.

3,Monitor Instance

最好监控某一块Physical Disk,而不要粗暴地监控total。可能一块Physical Disk的IO很忙,而其他Physical Disk很idle。

二,根据WaitType查看IO

1,数据文件的IO

如果SQL Server 出现IO bottlenect,那么在SQL Server 内部能够通过DMV sys.dm_exec_requests的wait_type,来check IO 问题。如果Request的wait_type长时间处于PageIOLatch_XX,那么说明IO不能很快完成。

当SQL Server 要去读或写一个Page的时候,首先会在Buffer Pool里寻找,如果在Buffer Pool中找到了,那么读写操作会继续进行,没有任何等待。如果没有找到,那么SQL Server 就会设置Wait_Type为PageIOLatch_EX(写)或PageIOLatch_SH(读),然后发起一个异步IO操作,将页面读入Buffer Pool中,在IO没有完成之前,Request将会保持在PageIOLatch_EX(写)或PageIOLatch_SH(读)的等待状态。IO消耗的时间越长,等待的时间越长。

2,日志文件的写入

日志文件以写为主,工作量由修改命令激发的事务数量决定。当SQL Server要写事务到日志文件时,如果Disk 不能及时完成IO请求,那么事务就无法提交,SQL Server 不得不进入WriteLog 等待状态,直到事务被成功记录到日志文件中,才会提交当前的事务。

如果request经常出现WriteLog的Wait type,说明事务日志的写请求不能被Disk及时完成,这种情况,对SQL Server 整体性能影响较大。

三,影响SQL Server Read/Write的factor

1,Physical Disk的IO能力

2,内存对Disk IO的影响

在SQL Server Engine 访问数据时,如果相应的data不存在于Buffer Pool,那么Buffer Manager 从Disk中的Data File(mdf 或 ndf)中将相应的data page读取到内存中。SQL Server 将data page缓存起来。理想情况下,只要SQL Server能够使用的内存充足,SQL Server 会将所有读取到内存的中Data Page缓存到Buffer Pool中。对于读取操作,只要相应的数据都缓存在内存中,Select 就不会有任何Disk IO。

当Buffer Pool空间不足时,SQL Server 激活 LazyWriter,主动将内存中一些很久没有使用的Data Cache和 Plan Cache 清除,mark为Free buffer,供其它Data Page使用。如果这些Page上的修改还没有被CheckPoint写回Disk,那么LazyWrite会将其写回。

3,碎片和压缩

如果数据页面或index 页面的碎片很多,每个页面存储的数据行较少,那么SQL Server 需要读写更多的Page。如果数据在页面里存储的非常紧凑,存储相同数据所消耗的Page越少,并且可以充分利用SQL Server 预读的优势,减少IO。

压缩技术不仅使数据占用的Disk 空间减少,而且能够减少IO。由于数据在写入Disk之间经过压缩处理,存储相同数据所消耗的Page减少,读取的Data Page会减少。压缩技术在一定程度上能够降低IO,但需要付出一定的代价:额外消耗少量的CPU和内存来解压缩。

4,利用多个Physical Disk实现Data File的并发读写

在DB中的FileGroup 创建多个File,将这些File存放到不同的Physical Disk上。File 分布到不同的Physical Disk上,IO也会分布到不同的Physical Disk上,这样能够实现数据的并发读取,提高读取性能。

对于日志文件,SQL Server会频繁的写事务日志。只要数据库发生修改,就会不断地写入日志文件。如果不能及时完成日志文件的IO,会导致事务的延迟提交,对性能的影响较大,所以,尽量将日志文件放到写入速度快的Disk上。SQL Server 顺序写事务日志,在一个时间点,SQL Server 只会写一个日志文件。在不同的Physical Disk上创建多个log file对性能基本没有帮助。

5,工作量

日志文件以写为主,工作量由修改命令申请的事务数量决定,日志文件是顺序写的,写入速度快于随机写。如果日志记录不能及时写入,那么Request会处于WriteLog等待状态,对系统整体性能影响较大。

数据文件写入的数据量由修改量决定,SQL Server除了设置bulk logged 恢复模式之外,没有太大的调整选项。

数据文件读取的数据量,由访问的数据量和Buffer Pool中缓存的数据量共同决定。如果访问的数据量减少或者内存缓存区增加,都可以降低SQL Server 从Physical Disk读取的Data Page数量。在内存不变的情况下,可以通过优化查询语句,减少数据访问量,来提高SQL Server 数据文件的读取性能。

数据文件

参考doc:

Windows Performance Monitor Disk Counters Explained

High Avg Disk Queue Length and finding the Cause

Disk Queue Length vs. Disk Latency Times: Which is Best for Measuring Database Performance

Disk IO Performance的更多相关文章

  1. Resolving SQL Server Disk IO bottlenecks

    网上看到这篇文章挺不错的,直接翻译过来.在尝试诊断SQL Server性能时,不要仅仅依赖某个单一的诊断数据,比如CPU的使用率.SQL Server磁盘性能,就得出结论却忽略的问题的根源.实际上,使 ...

  2. zabbix 自动发现 监控 硬盘读写 disk io

    直接 上配置: 1.配置文件 cat userparameter_harddisk.conf #discovery hard diskUserParameter=custom.vfs.discover ...

  3. Better Linux Disk Caching & Performance with vm.dirty_ratio & vm.dirty_background_ratio

    In previous posts on vm.swappiness and using RAM disks we talked about how the memory on a Linux gue ...

  4. kfk: async disk IO深度解析

    http://www.itpub.net/thread-1724044-1-1.html

  5. Performance Monitor4:监控SQL Server的IO性能

    SQL Server的IO性能受到物理Disk的IO延迟和SQL Server内部执行的IO操作的影响.在监控Disk性能时,最主要的度量值(metric)是IO延迟,IO延迟是指从Applicati ...

  6. Performance Monitor2:Peformance Counter

    Performance Counter 是量化系统状态或活动的一个数值,Windows Performance Monitor在一定时间间隔内(默认的取样间隔是15s)获取Performance Co ...

  7. [转]linux 系统监控、诊断工具之 IO wait

    1.问题: 最近在做日志的实时同步,上线之前是做过单份线上日志压力测试的,消息队列和客户端.本机都没问题,但是没想到上了第二份日志之后,问题来了: 集群中的某台机器 top 看到负载巨高,集群中的机器 ...

  8. 【转】Microsoft® SQL Server® 2012 Performance Dashboard Reports

    http://www.cnblogs.com/shanyou/archive/2013/02/12/2910232.html SQL Server Performance Dashboard Repo ...

  9. Measuring & Optimizing I/O Performance

    By Ilya Grigorik on June 23, 2009 Measuring and optimizing IO performance is somewhat of a black art ...

随机推荐

  1. spark 2.0 中 pyspark 对接 Ipython

    pyspark 2.0 对接 ipython 在安装spark2.0 后,以往的对接ipython方法失效,会报如下错错误: 因为在spark2.0后对接ipython的方法进行了变更我们只需要在py ...

  2. Maven+Spring Profile实现生产环境和开发环境的切换

    第一步 Maven Profile配置 <profiles> <profile> <id>postgres</id> <activation> ...

  3. 【原】iOS学习之三种拨打电话方式的比较

    拨打电话小编从网上找到三种,在这里做一些总结和比较 1.基本使用 NSString *str = [[NSMutableString alloc] initWithFormat:@"tel: ...

  4. [资源分享]yslow 与firebug 修复版本Firefox35【绿色版本下载】

    自从火狐也开始做版本帝后,相关查的插件越来越不好使了, 而且火狐集成自己的调试工具,也不是很好使用,Yslow 也坏掉了 找公司写c++修复了下 把yslow和Firebug 打包到一起,而且关闭自动 ...

  5. Hive文件存储格式

    hive文件存储格式 1.textfile textfile为默认格式   存储方式:行存储   磁盘开销大 数据解析开销大   压缩的text文件 hive无法进行合并和拆分 2.sequencef ...

  6. 懒加载lazyload

    什么是懒加载 懒加载就是当你做滚动到页面某个位置,然后再显示当前位置的图片,这样做可以减少页面请求. 懒加载:主要目的是作为服务器前端的优化,减少请求数或延迟请求数,一些图片非常多的网站中非常有用,在 ...

  7. Oozie_初识

    Oozie 任务调度框架(基于工作流) oozie运行于hadoop集群,对hive,mr,flume,Soop,spark,shell等框架进行任务流调度 如: job1-->job2 &am ...

  8. 1002. A+B for Polynomials (25)

    题目链接:https://www.patest.cn/contests/pat-a-practise/1002 原题如下: This time, you are supposed to find A+ ...

  9. *HDU 1392 计算几何

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  10. Django发送邮件

    1. 配置相关参数 如果用的是 阿里云的企业邮箱,则类似于下面: 在 settings.py 的最后面加上这些 EMAIL_BACKEND='django.core.mail.backends.smt ...