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!
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
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
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
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.
resource_address <> 0
You can answer this question by looking at the wait type of tasks waiting on specifically you are interested in IO waits
wait_duration_ms > 20 AND
wait_type LIKE '%PAGEIOLATCH%'
You might want to change 20ms base on your I/O subsystem
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