以下內容主要來源於網絡,同時結合了一部分自己的測試數據
介紹 (Introduction )
As DBAs, we all get to the point where we are asked to setup a new server for a specific environment. Setting up a new server is not a big thing but giving the answer to the question that “how well it will work” might be tricky.
作為DBA,我們所有人都被要求為特定環境設置新服務器。 設置新服務器不是一件大事,但是要回答“它將如何運行”這個問題可能會很棘手。
There are tons of items which we can setup to measure how well the newly installed server will response but here I will discuss one of the most important resource of the server “Disk”. Most often the disk is not measured correctly or I have seen environments where the disk response time has never been measured. I will discuss here a tool from Microsoft which is very handy and can solve your problem very quickly. The diskspd.exe!
我們可以設置很多項目來衡量新安裝的服務器將如何響應,但是在這里,我將討論服務器“磁盤”的最重要資源之一。 大多數情況下,磁盤測量不正確,或者我見過從未測量過磁盤響應時間的環境。 我將在這里討論Microsoft提供的一種非常方便的工具,它可以很快解決您的問題。 diskspd.exe!
It’s the superseding version of SQLIO which was previously used to measure IO response time for disk. The source code of diskspd.exe is hosted on GitHub. You can download this free utility from Microsoft’s website using this link.
它是SQLIO的替代版本,以前用於衡量磁盤的IO響應時間。 diskspd.exe的源代碼托管在GitHub上 。 您可以使用此鏈接從Microsoft網站下載此免費實用程序。
After you will download the utility you will get a zip file. Just unzip the file and it will give you the folders and files as shown in the below screenshot. You will be needing the exe of diskspd inside the folder “amd64fre” if you have a SQL Server 64-bit version (most of us will be having this).
下載該實用程序后,您將獲得一個zip文件。 只需解壓縮文件,它將為您提供文件夾和文件,如以下屏幕截圖所示。 如果您使用的是SQL Server 64位版本,則需要在“ amd64fre”文件夾中使用diskspd的exe文件(我們大多數人都擁有該版本)。

讓我們開始吧 (Let’s get started)
Now we can start the actual tests using the utility. To simplify things for the test we can copy appropriate executable file to a folder in C Drive like “C:\diskspd_test” and create a folder in the drive which you want to test like for this instance H Drive and I created a folder TestLoad in H Drive.
現在,我們可以使用該實用程序開始實際測試。 為了簡化測試,我們可以將適當的可執行文件復制到C驅動器中的文件夾,例如“ C:\ diskspd_test”,並在要測試的驅動器中創建一個文件夾,例如本實例H Drive,並在其中創建一個文件夾TestLoad。 H盤。
The utility is capable enough to create a good load file for you and test it for read and write. Though there are many ways to customize your testing but I will suggest you to start with a simple yet with solid results.
該實用程序足以為您創建一個良好的加載文件,並對其進行讀寫測試。 盡管有很多方法可以自定義您的測試,但是我建議您從一個簡單而可靠的結果開始。
Mentioned below is the test arguments I used. I will explain each argument I used.
下面提到的是我使用的測試參數。 我將解釋我使用的每個參數。
Sample Command Line Argument:
示例命令行參數:
diskspd -b64k –d120 –o32 –t4 –h –r –w25 –L –c2G D:\TestLoad\TestLoad.dat > diskspd_resultdetails.txt
diskspd -b64k –d120 –o32 –t4 –h –r –w25 –L –c2G D:\ TestLoad \ TestLoad.dat> diskspd_resultdetails.txt
- -b64k: This indicates that a 64KB block size will be used for the load. This is good because ideally speaking your drives should be formatted by 64K block size. Though you can increase or decrease it based on your custom built environment.
- -d120: This means that the duration of the test will be 120 seconds. You can span it to more time if you want to test the disk with larger and longer loads. Which is a good idea.
- -o32: This is the number of outstanding I/O operations which is like your queue length.
- -t4: This means that each file will have 4 threads attached to it. I have 4 core processor so I added 4 and you can customize it to match your server specifications.
- -h: This will disable the software and hardware buffering to mimic SQL Server.
- -r: The utility can perform sequential reads (default) or random read. I would prefer to use random reads. The r argument is to specifically ask utility to do only random reads.
- -w25: The utility can do reads and writes test and by default it only does the read. But we want read and writes both. It’s a good idea to split a SQL Server load to 25% Writing and 75% reading. Though you can test your disk as per your requirements like for log files you should only specify –w100 to only test writing.-w25:該實用程序可以讀取和寫入測試,並且默認情況下它僅讀取。 但是我們要同時讀寫。 將SQL Server的負載分成25%寫入和75%讀取是一個好主意。 盡管您可以按照日志文件等要求來測試磁盤,但僅應指定–w100以僅測試寫入。
- -L : 記錄IO延時的統計數據(Avglat )
- -c2G: This will create a test load file of 2 GB on the specified location.
- > “diskspd_resultdetails.txt”: This is the filename of the results. The file will be created in the C Drive where you will place the diskspd.exe file, in this case, “C:\diskspd_test”.
Well the test will run for 2 minutes in this case and it will do the specified work you mentioned in the arguments. After the test has been run completely it will generate the results file and then you will read and analyze the file.
那么在這種情況下,測試將運行2分鍾,它將完成您在參數中提到的指定工作。 完全運行測試后,它將生成結果文件,然后您將讀取並分析該文件。
讓我們繼續閱讀我的結果 (Let’s go ahead and read what my results are)
The first part of the results which is shown below tells us what arguments and settings the utility will use to test the load. So, all the arguments explained earlier are mentioned in further details by the utility itself.
結果的第一部分如下所示,它告訴我們實用程序將用來測試負載的參數和設置。 因此,實用程序本身會進一步詳細介紹前面解釋的所有參數。

中央處理器 (The CPU)
The second part of the results shows how the CPU behaved while the load was executed. All the results will have two parts, first will be detailed for each resource and the last will be average or total. So we can quickly go to the last part just to see how was the average CPU while the load was executed to see if we have CPU bottleneck or its perfectly suits our load.
結果的第二部分顯示了執行加載時CPU的行為。 所有結果將分為兩部分,第一部分將詳細說明每種資源,最后一部分是平均值或總計。 因此,我們可以快速轉到最后一部分,只是看看執行負載時的平均CPU狀況如何,看看我們是否有CPU瓶頸或它完全適合我們的負載。

磁盤 (The Disk)
The third part is the core of all the utility, the disk! This again has different parts in the results.
第三部分是磁盤的所有實用程序的核心! 這在結果中又有不同的部分。
First part shows the Total IO as a Summary to see how well the disk responded. You can see the “AvgLat” column to see the Average Latency of the disk for total IO. Not to go into the details of the latency but generally speaking it should remain under 20ms. If it goes beyond then you have serious issues with your server. (I know my system sucks but the drive is an OLD SATA III).
第一部分以匯總形式顯示總IO,以查看磁盤的響應情況。 您可以查看“ AvgLat”列,以查看磁盤的平均IO延遲。 不贅述延遲的細節,但是通常來說,它應該保持在20ms以下。 如果超出此范圍,則說明您的服務器存在嚴重問題。 (我知道我的系統很爛,但是驅動器是OLD SATA III)。
The I/Os can on the lower side as the load is divided on worker threads so you can directly go to the TOTAL column highlighted in the below screenshot which will show you the total load (in 64k block size in our case).
由於負載是在工作線程上分配的,因此I / O可以位於下方,因此您可以直接轉到下面的屏幕快照中突出顯示的TOTAL列,該列將向您顯示總負載(本例中為64k塊大小)。
The Second part shows Reads and third part shows Writes. This is most important part of the results. You can go into the details of every column but the Latency should be kept in mind as this is the main reason for slowness when the actual load will be executed by the users. This clearly shows how well your disk is performing under your load for reads and writes.
第二部分顯示讀取,第三部分顯示寫入。 這是結果中最重要的部分。 您可以進入每一列的詳細信息,但應牢記等待時間,因為這是用戶執行實際加載時速度緩慢的主要原因。 這清楚地顯示了磁盤在負載下的讀寫性能。
The last part of the results is dedicated to the latency and shows how well the disk performed while the load was executed. This numbers are in milliseconds and you can focus on minimum and maximum. So keep in mind that the best case scenario will be minimum and the worst case scenario will be max and that will be the time when your server will be in peak hours.
結果的最后一部分專用於等待時間,並顯示磁盤在執行加載時的性能。 此數字以毫秒為單位,您可以專注於最小值和最大值。 因此請記住,最好的情況是最小,最壞的情況是最大,這就是服務器處於高峰時段的時間。下圖表示 99%的寫操作等待在726ms以內

Now, after having the knowledge of this awesome utility, you can design multiple test load for different environment and run them so see how storage system and CPU is performing. The detailed tests can give your insight and you can modify the load of upgrade your resources accordingly to your needs.
現在,在了解了該實用工具之后,您可以針對不同的環境設計多個測試負載並運行它們,從而了解存儲系統和CPU的性能。 詳細的測試可以提供您的見解,並且您可以根據需要修改資源升級的負擔。
重點:
1.測試結果解讀
- thread:生成IO的線程的編號
- bytes:為測試傳輸的總字節數
- I/Os:為測試執行的IO操作總數
- MB/s:吞吐量,以MB /秒為單位
- I/O per s:每秒的IO操作數
- AvgLat:測試的所有IO操作的平均延遲
- IopsStdDev:每秒IO操作的標准偏差
- LatStdDev:測試遇到的延遲的標准偏差
- file:IO測試中使用的文件的路徑
2. Microsoft建議日志延遲應該在1-5ms到數據延遲應該在4-20ms之間(看99th那一行)。
3. 對於IO 匯總 AvgLat ,一般建議保證在20ms以下。
3. 我的測試指令:
a) diskspd -c2G -b4k -t6 -d120 -o32 -w25 -h -r -L D:\DISKTEST\DiskTest.dat>DiskTestResult.txt
解讀:測試文件大小為2G,Block4K,CPU6核,測試時間120秒,排隊隊列32,25%的寫操作,disable緩存,使用隨機讀寫模式,記錄IO延時統計數據
結果:(普通硬盤)
Total IO thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | LatStdDev | file ----------------------------------------------------------------------------------------------------- 0 | 38486016 | 9396 | 0.31 | 78.29 | 408.565 | 118.066 | D:\DISKTEST\DiskTest.dat (2048MiB) 1 | 38592512 | 9422 | 0.31 | 78.51 | 407.136 | 118.476 | D:\DISKTEST\DiskTest.dat (2048MiB) 2 | 38592512 | 9422 | 0.31 | 78.51 | 407.246 | 117.989 | D:\DISKTEST\DiskTest.dat (2048MiB) 3 | 38256640 | 9340 | 0.30 | 77.82 | 410.640 | 119.603 | D:\DISKTEST\DiskTest.dat (2048MiB) 4 | 38367232 | 9367 | 0.30 | 78.05 | 409.907 | 119.284 | D:\DISKTEST\DiskTest.dat (2048MiB) 5 | 38563840 | 9415 | 0.31 | 78.45 | 407.491 | 118.897 | D:\DISKTEST\DiskTest.dat (2048MiB) ----------------------------------------------------------------------------------------------------- total: 230858752 | 56362 | 1.83 | 469.63 | 408.493 | 118.727 Read IO thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | LatStdDev | file ----------------------------------------------------------------------------------------------------- 0 | 28897280 | 7055 | 0.23 | 58.78 | 427.586 | 120.882 | D:\DISKTEST\DiskTest.dat (2048MiB) 1 | 28798976 | 7031 | 0.23 | 58.58 | 426.931 | 121.353 | D:\DISKTEST\DiskTest.dat (2048MiB) 2 | 28774400 | 7025 | 0.23 | 58.53 | 426.371 | 121.530 | D:\DISKTEST\DiskTest.dat (2048MiB) 3 | 28983296 | 7076 | 0.23 | 58.96 | 429.600 | 122.549 | D:\DISKTEST\DiskTest.dat (2048MiB) 4 | 28844032 | 7042 | 0.23 | 58.68 | 428.898 | 122.391 | D:\DISKTEST\DiskTest.dat (2048MiB) 5 | 29061120 | 7095 | 0.23 | 59.12 | 425.737 | 122.086 | D:\DISKTEST\DiskTest.dat (2048MiB) ----------------------------------------------------------------------------------------------------- total: 173359104 | 42324 | 1.38 | 352.66 | 427.521 | 121.809 Write IO thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | LatStdDev | file ----------------------------------------------------------------------------------------------------- 0 | 9588736 | 2341 | 0.08 | 19.51 | 351.242 | 86.808 | D:\DISKTEST\DiskTest.dat (2048MiB) 1 | 9793536 | 2391 | 0.08 | 19.92 | 348.926 | 86.413 | D:\DISKTEST\DiskTest.dat (2048MiB) 2 | 9818112 | 2397 | 0.08 | 19.97 | 351.195 | 84.981 | D:\DISKTEST\DiskTest.dat (2048MiB) 3 | 9273344 | 2264 | 0.07 | 18.86 | 351.381 | 86.255 | D:\DISKTEST\DiskTest.dat (2048MiB) 4 | 9523200 | 2325 | 0.08 | 19.37 | 352.387 | 86.911 | D:\DISKTEST\DiskTest.dat (2048MiB) 5 | 9502720 | 2320 | 0.08 | 19.33 | 351.693 | 87.491 | D:\DISKTEST\DiskTest.dat (2048MiB) ----------------------------------------------------------------------------------------------------- total: 57499648 | 14038 | 0.46 | 116.97 | 351.126 | 86.480 total: %-ile | Read (ms) | Write (ms) | Total (ms) ---------------------------------------------- min | 62.458 | 53.469 | 53.469 25th | 349.814 | 306.970 | 333.438 50th | 406.073 | 336.431 | 385.444 75th | 491.828 | 383.219 | 469.898 90th | 584.877 | 471.069 | 562.338 95th | 649.373 | 514.116 | 625.250 99th | 801.007 | 601.934 | 775.135
b) diskspd -c2G -b4k -t6 -d120 -o32 -w25 -h -r -L C:\DISKTEST\DiskTest.dat>DiskTestResult.txt
解讀:測試文件大小為2G,Block4K,CPU6核,測試時間120秒,排隊隊列32,25%的寫操作,disable緩存,使用隨機讀寫模式,記錄IO延時統計數據
結果:(SSD硬盤)
Total IO thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | LatStdDev | file ----------------------------------------------------------------------------------------------------- 0 | 1500712960 | 366385 | 11.93 | 3052.90 | 10.483 | 7.325 | C:\DISKTEST\DiskTest.dat (2048MiB) 1 | 1482653696 | 361976 | 11.78 | 3016.16 | 10.611 | 7.504 | C:\DISKTEST\DiskTest.dat (2048MiB) 2 | 1499291648 | 366038 | 11.91 | 3050.01 | 10.493 | 7.315 | C:\DISKTEST\DiskTest.dat (2048MiB) 3 | 1504612352 | 367337 | 11.96 | 3060.83 | 10.456 | 7.276 | C:\DISKTEST\DiskTest.dat (2048MiB) 4 | 1507360768 | 368008 | 11.98 | 3066.42 | 10.437 | 7.257 | C:\DISKTEST\DiskTest.dat (2048MiB) 5 | 1508380672 | 368257 | 11.99 | 3068.50 | 10.430 | 7.260 | C:\DISKTEST\DiskTest.dat (2048MiB) ----------------------------------------------------------------------------------------------------- total: 9003012096 | 2198001 | 71.54 | 18314.83 | 10.485 | 7.323 Read IO thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | LatStdDev | file ----------------------------------------------------------------------------------------------------- 0 | 1124831232 | 274617 | 8.94 | 2288.24 | 9.188 | 6.477 | C:\DISKTEST\DiskTest.dat (2048MiB) 1 | 1111691264 | 271409 | 8.83 | 2261.51 | 9.319 | 6.683 | C:\DISKTEST\DiskTest.dat (2048MiB) 2 | 1125097472 | 274682 | 8.94 | 2288.79 | 9.210 | 6.502 | C:\DISKTEST\DiskTest.dat (2048MiB) 3 | 1128062976 | 275406 | 8.96 | 2294.82 | 9.186 | 6.499 | C:\DISKTEST\DiskTest.dat (2048MiB) 4 | 1129492480 | 275755 | 8.98 | 2297.73 | 9.147 | 6.421 | C:\DISKTEST\DiskTest.dat (2048MiB) 5 | 1130487808 | 275998 | 8.98 | 2299.75 | 9.159 | 6.474 | C:\DISKTEST\DiskTest.dat (2048MiB) ----------------------------------------------------------------------------------------------------- total: 6749663232 | 1647867 | 53.64 | 13730.84 | 9.201 | 6.509 Write IO thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | LatStdDev | file ----------------------------------------------------------------------------------------------------- 0 | 375881728 | 91768 | 2.99 | 764.66 | 14.360 | 8.287 | C:\DISKTEST\DiskTest.dat (2048MiB) 1 | 370962432 | 90567 | 2.95 | 754.65 | 14.484 | 8.441 | C:\DISKTEST\DiskTest.dat (2048MiB) 2 | 374194176 | 91356 | 2.97 | 761.22 | 14.353 | 8.213 | C:\DISKTEST\DiskTest.dat (2048MiB) 3 | 376549376 | 91931 | 2.99 | 766.01 | 14.260 | 8.107 | C:\DISKTEST\DiskTest.dat (2048MiB) 4 | 377868288 | 92253 | 3.00 | 768.70 | 14.294 | 8.186 | C:\DISKTEST\DiskTest.dat (2048MiB) 5 | 377892864 | 92259 | 3.00 | 768.75 | 14.232 | 8.106 | C:\DISKTEST\DiskTest.dat (2048MiB) ----------------------------------------------------------------------------------------------------- total: 2253348864 | 550134 | 17.91 | 4583.99 | 14.330 | 8.224 total: %-ile | Read (ms) | Write (ms) | Total (ms) ---------------------------------------------- min | 1.192 | 5.102 | 1.192 25th | 7.417 | 11.318 | 7.665 50th | 8.113 | 12.598 | 8.534 75th | 8.795 | 13.934 | 10.418 90th | 9.455 | 15.456 | 13.655 95th | 10.064 | 37.290 | 15.524 99th | 47.431 | 52.469 | 48.958
結論:對比以上紅色hightlight的數值,我們不難發現ssd硬盤與普通硬盤差異是很大的。
5.寫了一個批處理:diskiotest.bat
diskspd.exe -c2G -b4k -t4 -d120 -o20 -w50 -h -r -L C:\DiskIOTest\DiskTest.dat>DiskTestResult-C.txt diskspd.exe -c2G -b4k -t4 -d120 -o20 -w50 -h -r -L D:\DiskIOTest\DiskTest.dat>DiskTestResult-D.txt diskspd.exe -c2G -b4k -t4 -d120 -o20 -w50 -h -r -L E:\DiskIOTest\DiskTest.dat>DiskTestResult-E.txt rd /S /Q C:\DiskIOTest rd /S /Q D:\DiskIOTest rd /S /Q E:\DiskIOTest