原文:SQL Server 服务器磁盘测试之SQLIO篇
数据库调优工作中,有一部分是需要排查IO问题的,例如IO的速度或者RAID级别无法响应高并发下的快速请求。最常见的就是查看磁盘每次读写的响应速度,通过性能计数器Avg.Disk sec/Read(Write)我们可以很直观的看到他们。不同的业务,繁忙程度也不同,需要什么样的IO做支撑?难道都用最高配的IO去配置硬件吗?能否通过一些经验和基线来判断当下磁盘环境是否能满足需求呢?
手上有4块 Inter SSD DC S3500 Series 600GB硬盘做成的RAID1两块,我们就拿它来练练手吧!
SQLIO是微软提供的一款IO测试工具,下载地址:http://www.microsoft.com/en-us/download/details.aspx?id=20163
下载完毕后,一路Next安装完毕,默认目录是:C:\Program Files (x86)\SQLIO
前期准备工作:
1、为SQLIO.exe排除数据执行保护
2、去掉图示上的勾
下面我们来熟悉一下SQLIO的参数:
-o
Number of outstanding I/O requests per thread. When attempting to determine the capacity of a given volume or set of volumes, start with a reasonable number for this and increase until disk saturation is reached (that is, latency starts to increase without an additional increase in throughput or IOPs). Common values for this are 8, 16, 32, 64, and 128.
Keep in mind that this setting is the number of outstanding I/Os per thread.
每个线程可以发起多个IO请求
-LS
Instructs SQLIO to capture disk latency information. Capturing latency data is recommended when testing a system.
开启该参数打印出磁盘延迟信息,必选项。
-k
Specify either R or W (read or write). Both reads and writes should be tested. Keep in mind that the storage array cache may absorb a good amount of write activity and potentially skew results. Ensure that the duration is long enough to saturate the cache in order to get a true measure of storage capacity.
指定读操作-R或者写操作W
-s
Duration of test (in seconds). For initial tests, running for 5-10 minutes per I/O size is recommended to get a good idea of I/O performance.
每个批次执行的时间,推荐每个size的IO请求运行5-10分钟,单位为秒
-b
Size of the I/O request in kbytes. For random I/O, 8 KB and 64 KB are as many values as are need to be tested. The most common random I/O size for SQL Server is 8 KB. For random I/O, pay close attention to the number of I/Os per second and latency. For sequential I/O, test a range of sizes (4, 8, 16, 32, 64, 128, 256) and pay attention to throughput and latency.
指定读写的IO大小,单位是KB。8KB是SQL Server随机读写最常用的块大小,其次是64KB。
对于随机IO测试,密切注意每秒的IO请求数和延迟;
对于顺序IO测试,多注意每秒的吞吐量和延迟。
-f
Type of I/O to issue. Either ‘random’ or ‘sequential’.
指定IO的请求方式,随机Random或者顺序Sequential
-F
Name of the file that will contain a list of the test file(s) used by SQLIO.
指定SQLIO测试使用的文件
测试目的:
查看不同的卷簇大小(默认4KB/64KB)对SQL Server常用IO操作单位(8KB/64KB)的影响
测试热身:
首先,我们先理清几点 Keep in your mind:
1、对于随机Random读写,我们看重的是每秒的IO操作次数,即 IO/sec,IO Operations
2、对于顺序Sequential读写,我们看重的是每秒的吞吐量,即 MB/sec
3、对于SQL Server数据文件,更多的操作是随机读写。
读:SQL Server应客户端查询需求,将不在内存中的记录从磁盘上随机的位置读入内存;写:SQL Server CheckPoint或者Lazy
Writer出动时,将SQL Server Buffer Cache中大量的Dirty Page写入磁盘上随机的位置。4、对于SQL Server日志文件,更多的操作是顺序读写。
读:当进行日志备份或者LogReader工作时,SQL Server将顺序的读取日志。
写:顺序写操作是日志的再正常不过的行为了
5、如下表格,列出了SQL Server常见行为下的IO操作单位大小,可以看到,8KB和64KB依次是SQL Server最常操作的IO单位大小
6、SQL
Server分配数据的最小单位是8KB,而Windows存储数据也有最小的分配单位,那就是卷簇,而且该值格式化磁盘分区时是可选的,默认值即为4KB。查看指定分区卷簇大小:fsutil fsinfo ntfsinfo d:
测试过程:
1、两块分区分别为D盘和E盘,其中D盘簇大小为默认4KB,E盘簇大小为64KB
2、D盘的测试代码如下:
Rem 8KB随机写sqlio -kW -t8 -s90 -dD -o1 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t16 -s90 -dD -o1 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t32 -s90 -dD -o1 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o1 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o2 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o4 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o8 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o16 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txt Rem 64KB随机写sqlio -kW -t8 -s90 -dD -o1 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t16 -s90 -dD -o1 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t32 -s90 -dD -o1 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o1 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o2 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o4 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o8 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o16 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txt Rem 8KB随机读sqlio -kR -t8 -s90 -dD -o1 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t16 -s90 -dD -o1 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t32 -s90 -dD -o1 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o1 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o2 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o4 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o8 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o16 -frandom -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txt Rem 64KB随机读sqlio -kR -t8 -s90 -dD -o1 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t16 -s90 -dD -o1 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t32 -s90 -dD -o1 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o1 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o2 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o4 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o8 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o16 -frandom -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txt Rem 8KB顺序写sqlio -kW -t8 -s90 -dD -o1 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t16 -s90 -dD -o1 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t32 -s90 -dD -o1 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o1 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o2 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o4 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o8 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o16 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txt Rem 64KB顺序写sqlio -kW -t8 -s90 -dD -o1 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t16 -s90 -dD -o1 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t32 -s90 -dD -o1 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o1 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o2 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o4 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o8 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dD -o16 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txt Rem 8KB顺序读sqlio -kR -t8 -s90 -dD -o1 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t16 -s90 -dD -o1 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t32 -s90 -dD -o1 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o1 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o2 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o4 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o8 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o16 -fsequential -b8 -BH -LS Testfile.dat >>4KB_Cluster_Test.txt Rem 64KB顺序读sqlio -kR -t8 -s90 -dD -o1 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t16 -s90 -dD -o1 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t32 -s90 -dD -o1 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o1 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o2 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o4 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o8 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dD -o16 -fsequential -b64 -BH -LS Testfile.dat >>4KB_Cluster_Test.txt3、E盘测试脚本:
Rem 8KB随机写sqlio -kW -t8 -s90 -dE -o1 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t16 -s90 -dE -o1 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t32 -s90 -dE -o1 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o1 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o2 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o4 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o8 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o16 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txt Rem 64KB随机写sqlio -kW -t8 -s90 -dE -o1 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t16 -s90 -dE -o1 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t32 -s90 -dE -o1 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o1 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o2 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o4 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o8 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o16 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txt Rem 8KB随机读sqlio -kR -t8 -s90 -dE -o1 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t16 -s90 -dE -o1 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t32 -s90 -dE -o1 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o1 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o2 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o4 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o8 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o16 -frandom -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txt Rem 64KB随机读sqlio -kR -t8 -s90 -dE -o1 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t16 -s90 -dE -o1 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t32 -s90 -dE -o1 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o1 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o2 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o4 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o8 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o16 -frandom -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txt Rem 8KB顺序写sqlio -kW -t8 -s90 -dE -o1 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t16 -s90 -dE -o1 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t32 -s90 -dE -o1 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o1 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o2 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o4 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o8 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o16 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txt Rem 64KB顺序写sqlio -kW -t8 -s90 -dE -o1 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t16 -s90 -dE -o1 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t32 -s90 -dE -o1 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o1 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o2 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o4 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o8 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kW -t64 -s90 -dE -o16 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txt Rem 8KB顺序读sqlio -kR -t8 -s90 -dE -o1 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t16 -s90 -dE -o1 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t32 -s90 -dE -o1 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o1 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o2 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o4 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o8 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o16 -fsequential -b8 -BH -LS Testfile.dat >>64KB_Cluster_Test.txt Rem 64KB顺序读sqlio -kR -t8 -s90 -dE -o1 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t16 -s90 -dE -o1 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t32 -s90 -dE -o1 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o1 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o2 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o4 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o8 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtsqlio -kR -t64 -s90 -dE -o16 -fsequential -b64 -BH -LS Testfile.dat >>64KB_Cluster_Test.txtNote:如果您对当前要测试的磁盘性能比较了解,您可以将每组测试行数控制在4-5行甚至更少,以此来节省测试时间,比如就将 -t 为8、16的测试行删除
待所有的测试跑完后,我们使用SqlioAnalyzer这个工具来导入测试结果4KB_Cluster_Test.txt和64KB_Cluster_Test.txt,下载地址:http://www.meauxsoft.com/SqlioAnalyzer.html
安装后,打开 File→Open,找到 txt路径,导入:
点击Export按钮,将数据导出为CSV文件
然后只留下每一组中测试值最高的行:整理后得到:
前面提到过,对于随机IO读写操作,我们着重关注单位时间内的IO操作次数 IO/Sec;
对于顺序IO读写操作,我们着重关注单位时间内的吞吐量 MB/Sec
上图中已经把需要关注的内容用颜色加以区分,接下来为了使展示更易懂,我制作了直方图:
图中可以很直观的看出,除了sequential_Write_64KB时簇为64KB比8KB稍低外,其它情况下,64KB总是比默认值4KB要有优势。
由此也证明了正如SqlioAnalyzer中提示的那样:
当你格式化磁盘的时候,请指定簇大小为64KB!!
另外NTFS格式的单独的磁盘,对齐方式现在总是为1024KB了,即图中所示的StartingOffset
测试总结:
实践是检验真理的唯一标准,您今后在为SQL
Server创建磁盘的时候,还使用默认的4KB卷簇大小吗?