From Slava Ok's blog, but I'm so tired of seeing good information on blogs "disappear" when I need to reference back to it, so I've had to copy it to my own blog, Slava, thankyou, link to Original: http://blogs.msdn.com/slavao/archive/2006/11/14/sqlosdmv-s-continue.aspx
One can run lots of interesting queries using this view. You can even use this view to perform deadlock detection that is not resolvable by deadlock monitor, DM. For example if you have tasks waiting on external resources such as extended stored procedures and blocking others from running. This type of deadlock DM can’t detect but you can!
- Q. How many tasks are currently waiting?
This query will give you an idea of how many tasks are waiting in the system. You can use this information to understand blocking characteristics of your load
- Q. How many tasks that assigned to a worker (thread/fiber) are waiting?
where wait_type <> 'THREADPOOL’
This query shows how many threads are actively running in the system. Latter on I will show how to find out if number of threads can be increased
- What are the tasks waiting on?
group by wait_type
order by count (*) desc
One can use this query to investigate possible bottlenceks of an active load. This query groups tasks by wait type – it can’t be directly use to identify the actual bottlenecks on the system. The query gives you an idea about the wait characteristics of your load
- Q. Does my load have an active resource bottleneck?
You can answer this question by looking at the resource address that tasks are blocked on. Keep in mind that not all wait types have resource associated with them.
WHERE resource_address <> 0
group by resource_address
order by count (*) desc
- Q: Is my system can be possibly bottlenecked on I/O?
You can answer this question by looking at the wait type of tasks waiting on specifically you are interested in IO waits
where wait_duration_ms > 20 AND
wait_type LIKE '%PAGEIOLATCH%'
You might want to change 20ms base on your I/O subsystem
- Q: Does my load have long waiting chains?
This information is particular interesting to understand if a single tasks, for example one that generated long I/O, blocks others. If this happens you will have a way to improve your scalability by figuring how to remove or minimize chain length.
WITH TaskChain (
-- Anchor member definition: use self join so that we output
-- Only tasks that blocking others and remove dupliates
A.waiting_task_address As ChainId,
0 AS Level
sys.dm_os_waiting_tasks as A
sys.dm_os_waiting_tasks as B
A.waiting_task_address = B.blocking_task_address
A.blocking_task_address IS NULL
-- Recursive member definition: Get to the next level waiting
Level + 1
sys.dm_os_waiting_tasks AS A
TaskChain AS B
B.waiting_task_address = A.blocking_task_address
If there are no chains, your load is not CPU bound and you see long waits on THREADPOOL, you might improve your throughput by increasing a number of threads in the system.
Keep in mind that you can extend this query to perform your own deadlock detection.
You can also find out more information about each individual wait_type here