Hi,
I ran into strange issue on our sql server 2008r2 server. While running analysis of how fast our SAN is, I put together stored procedure that captures IO stalls and wait types counters (and some others as well), and I included it at the beginning and the end of some of our intensive processes (to measure performance). Basically this proc loads counter values into WaitTypes, and IO_Stalls user tables (see section of the code below).
Here is interesting part: when I run this proc manually, it loads both tables. When proc runs within the process (other stored procedures), second statement never loads any data (IO stalls).
How is this possible, any ideas?
--1. Load waits: ;with 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 from sys.dm_os_wait_stats where wait_type not in (N'CLR_SEMAPHORE',N'LAZYWRITER_SLEEP',N'RESOURCE_QUEUE',N'SLEEP_TASK', N'SLEEP_SYSTEMTASK',N'SQLTRACE_BUFFER_FLUSH',N'WAITFOR', N'LOGMGR_QUEUE',N'CHECKPOINT_QUEUE', N'REQUEST_FOR_DEADLOCK_SEARCH',N'XE_TIMER_EVENT',N'BROKER_TO_FLUSH',N'BROKER_TASK_STOP',N'CLR_MANUAL_EVENT', N'CLR_AUTO_EVENT',N'DISPATCHER_QUEUE_SEMAPHORE', N'FT_IFTS_SCHEDULER_IDLE_WAIT', N'XE_DISPATCHER_WAIT', N'XE_DISPATCHER_JOIN', N'SQLTRACE_INCREMENTAL_FLUSH_SLEEP', N'ONDEMAND_TASK_QUEUE', N'BROKER_EVENTHANDLER', N'SLEEP_BPOOL_FLUSH')) --etc insert into StatsDB.dbo.WaitTypes(date_id, date_time, wait_type, wait_time_s, pct, running_pct) select @Date_id, getdate() as date_time, W1.wait_type, cast(W1.wait_time_s as decimal(12,2)) as wait_time_s, cast(W1.pct as decimal(12,2)) as pct, cast(sum(W2.pct) as decimal(12,2)) as running_pct from Waits W1 join Waits W2 on W2.rn <= W1.rn group by W1.rn, W1.wait_type, W1.wait_time_s, W1.pct having sum(W2.pct) - W1.pct < 99; --percentage threshold --2. Load IO stalls: insert into StatsDB.dbo.IO_Stalls(date_id, date_time, database_name, physical_name, io_stall_read_ms, num_of_reads, avg_read_stall_ms, io_stall_write_ms, num_of_writes, avg_write_stall_ms, io_stalls, total_io, avg_io_stall_ms) select @Date_id, getdate() as date_time, db_name(fs.database_id) as database_name, mf.physical_name, io_stall_read_ms, num_of_reads, cast(io_stall_read_ms/(1.0 + num_of_reads) as numeric(10,1)) as [avg_read_stall_ms], io_stall_write_ms, num_of_writes, cast(io_stall_write_ms/(1.0 + num_of_writes) as numeric(10,1)) as [avg_write_stall_ms], io_stall_read_ms + io_stall_write_ms as [io_stalls], num_of_reads + num_of_writes as [total_io], cast((io_stall_read_ms + io_stall_write_ms)/(1.0 + num_of_writes + num_of_reads) as numeric(10,1)) as [avg_io_stall_ms] from sys.dm_io_virtual_file_stats(null,null) as fs join sys.master_files mf on mf.database_id = fs.database_id and fs.file_id = mf.file_id order by avg_io_stall_ms desc;
Pedja