One of the DMVs I try to utilize on any engagement where customers are complaining about disk issues is the sys.dm_io_virtual_file_stats DMV where you can look at the IO stalls for both reads and writes. The sys.dm_io_virtual_file_stats DMV will show an IO Stall when any wait occurs to access a physical data file. IO Stalls are recorded at the file level and you can also obtain the IO Stalls at the database level directly out of the DMV.
By getting this information it is very easy to ORDER BY io_stall_read_ms, io_stall_write_ms, or by io_stall which is an accumulation of reads and writes.
One addition step I have made in the script below is mapping to the sys.master_files catalog view and using the substring function to get the physical disk drive letter. You will now be able to see IO Stall activity at the file, database, and the drive letter. You can then use Reporting Services or simply use Excel to get a quick view of which of these is absorbing most of the IO Stall impact.
If you use Excel 2007, one of the interesting strategies is to use the Chart Advisor from Live Labs.
http://www.officelabs.com/projects/chartadvisor/Pages/default.aspx
This analysis can help make decisions around table partitioning and potentially file and index placement. Of course, this will all depend on the customer's SAN and other constraints.
Note: Mount points will make getting the drive letter less effective. If you are using mount points then just ignore the drive letter column.
SELECT a.io_stall, a.io_stall_read_ms, a.io_stall_write_ms, a.num_of_reads,
a.num_of_writes,
--a.sample_ms, a.num_of_bytes_read, a.num_of_bytes_written, a.io_stall_write_ms,
( ( a.size_on_disk_bytes / 1024 ) / 1024.0 ) AS size_on_disk_mb,
db_name(a.database_id) AS dbname,
b.name, a.file_id,
db_file_type = CASE
WHEN a.file_id = 2 THEN'Log'
ELSE 'Data'
END,
UPPER(SUBSTRING(b.physical_name, 1, 2))AS disk_location
FROM sys.dm_io_virtual_file_stats (NULL, NULL) a
JOIN sys.master_files bON a.file_id = b.file_id
AND a.database_id = b.database_id
ORDER BY a.io_stall DESC
For those looking at disk issues, I have pasted the general guidance on the avg. reads/sec and avg. writes/sec values for perfmon. By using the script above and the guidance here on perfmon, you should be able to take the next steps in addressing disk performance issues with your customers.
I/O Bottlenecks
SQL Server performance depends heavily on the I/O subsystem. Unless your database fits into physical memory, SQL Server constantly brings database pages in and out of the buffer pool. This generates substantial I/O traffic. Similarly, the log records need to be flushed to the disk before a transaction can be declared committed. And finally, SQL Server uses TempDB for various purposes such as to store intermediate results, to sort, to keep row versions and so on. So a good I/O subsystem is critical to the performance of SQL Server.
Access to log files is sequential except when a transaction needs to be rolled back while access to data files, including TempDB, is randomly accessed. So as a general rule, you should have log files on a separate physical disk than data files for better performance. The focus of this paper is not how to configure your I/O devices but to describe ways to identify if you have I/O bottleneck. Once an I/O bottleneck is identified, you may need to reconfigure your I/O subsystem.
If you have a slow I/O subsystem, your users may experience performance problems such as slow response times, and tasks that abort due to timeouts.
You can use the following performance counters to identify I/O bottlenecks. Note, these AVG values tend to be skewed (to the low side) if you have an infrequent collection interval. For example, it is hard to tell the nature of an I/O spike with 60-second snapshots. Also, you should not rely on one counter to determine a bottleneck; look for multiple counters to cross check the validity of your findings.
When using above counters, you may need to adjust the values for RAID configurations using the following formulas.
For example, you have a RAID-1 system with two physical disks with the following values of the counters.
In that case, you are encountering (80 + (2 * 70))/2 = 110 I/Os per disk and your disk queue length = 5/2 = 2.5 which indicates a border line I/O bottleneck."
另外可以利用下面的脚本定期IO信息做比对分析:
SET NOCOUNTON
DECLARE @IOStatsTABLE (
[database_id][smallint]NOT NULL,
[file_id][smallint]NOT NULL,
[num_of_reads][bigint]NOT NULL,
[num_of_bytes_read][bigint]NOT NULL,
[io_stall_read_ms][bigint]NOT NULL,
[num_of_writes][bigint]NOT NULL,
[num_of_bytes_written][bigint]NOT NULL,
[io_stall_write_ms][bigint]NOT NULL)
INSERTINTO @IOStats
SELECT database_id,
vio.file_id,
num_of_reads,
num_of_bytes_read,
io_stall_read_ms,
num_of_writes,
num_of_bytes_written,
io_stall_write_ms
FROM sys.dm_io_virtual_file_stats(NULL,NULL) vio
DECLARE @StartTime datetime, @DurationInSecsint
SET @StartTime= GETDATE()
WAITFOR DELAY'00:05:00'
SET @DurationInSecs= DATEDIFF(ss, @startTime, GETDATE())
SELECT DB_NAME(vio.database_id)AS [Database],
mf.nameAS [Logical name],
mf.type_descAS [Type],
(vio.io_stall_read_ms- old.io_stall_read_ms)/ CASE(vio.num_of_reads-old.num_of_reads)WHEN 0THEN 1ELSE vio.num_of_reads-old.num_of_readsEND AS[Ave read speed(ms)],
vio.num_of_reads- old.num_of_readsAS [Noof reads over period],
CONVERT(DEC(14,2),(vio.num_of_reads- old.num_of_reads)/ (@DurationInSecs *1.00))AS [Noof reads/sec],
CONVERT(DEC(14,2),(vio.num_of_bytes_read- old.num_of_bytes_read)/ 1048576.0)AS [Tot MBread over period],
CONVERT(DEC(14,2),((vio.num_of_bytes_read- old.num_of_bytes_read)/ 1048576.0)/ @DurationInSecs)AS [Tot MBread/sec],
(vio.num_of_bytes_read- old.num_of_bytes_read)/ CASE(vio.num_of_reads-old.num_of_reads)WHEN 0THEN 1ELSE vio.num_of_reads-old.num_of_readsEND AS[Ave read size(bytes)],
(vio.io_stall_write_ms- old.io_stall_write_ms)/ CASE(vio.num_of_writes-old.num_of_writes)WHEN 0THEN 1ELSE vio.num_of_writes-old.num_of_writesEND AS[Ave write speed (ms)],
vio.num_of_writes- old.num_of_writesAS [Noof writes over period],
CONVERT(DEC(14,2),(vio.num_of_writes- old.num_of_writes)/ (@DurationInSecs *1.00))AS [Noof writes/sec],
CONVERT(DEC(14,2),(vio.num_of_bytes_written- old.num_of_bytes_written)/1048576.0)AS [Tot MB writtenover period],
CONVERT(DEC(14,2),((vio.num_of_bytes_written- old.num_of_bytes_written)/1048576.0)/ @DurationInSecs)AS [Tot MB written/sec],
(vio.num_of_bytes_written-old.num_of_bytes_written)/ CASE(vio.num_of_writes-old.num_of_writes)WHEN 0THEN 1ELSE vio.num_of_writes-old.num_of_writesEND AS[Ave write size (bytes)],
mf.physical_nameAS [Physicalfile name],
size_on_disk_bytes/1048576AS [File sizeon disk(MB)]
FROM sys.dm_io_virtual_file_stats(NULL,NULL) vio,
sys.master_files mf,
@IOStats old
WHERE mf.database_id= vio.database_idAND
mf.file_id= vio.file_idAND
old.database_id= vio.database_idAND
old.file_id= vio.file_idAND
((vio.num_of_bytes_read- old.num_of_bytes_read)+ (vio.num_of_bytes_written- old.num_of_bytes_written))> 0
ORDERBY ((vio.num_of_bytes_read- old.num_of_bytes_read)+ (vio.num_of_bytes_written- old.num_of_bytes_written))DESC
GO