Thread
Thread Scheduling
Scheduler
The waiter list is a list of threads which are suspended and waiting for a resource. This is not a queue as there is no order in which the thread will get the resource.There is no parameter which define the maximum time a thread can be in the waiter list. Theoretically there is no limit but the timeout specified in the query execution session may take effect. While waiting in the Water List , the thread might get canceled due to the execution time out.The Waiter List can be examined by querying the DMV sys.dm_os_waiting_tasks.
The Runnable queue is a pure First-In-First-Out (FIFO) queue.When a thread moves from Waiter List it joins at the bottom of the Runnable queue. We can see the size of runnable queue by looking into the column of runnable_tasks_count column in sys.dm_os_schedules.There is special case when resource governor enabled and relative priorities assigned to multiple workload group for a resource pool.Possible values for priorities are High,Medium and Low which equate to 9,3 and 1. It means that 9 high priority thread and 3 Medium priority thread can override a low priority thread in the Runnable queue.
State of threads
There is case where thread by pass the Suspended state and directly move to the Runnable from Running and this is called quantum exhaustion.If a thread does not need to wait for any resources, it will continue to run till its quantum is exhausted. The quantum is fixed to 4ms and not configurable. The last column of the DMV sys.dm_os_schedulers define this value. Even if the thread does not need to wait for any resources,after the completion of its quantum time, it will move out of the processor and its state change from Running to Runnable. The thread move directly from Processor to bottom of Runnable queue bypassing the waiter list as it does not need to wait for a resource.
Below script shows the relationship between various DMV
SELECT
[dot].[scheduler_id],
[task_state],
COUNT (*) AS [task_count]FROMsys.dm_os_schedulers dos INNER JOIN sys.dm_os_workers dow ON dos.scheduler_address=dow.scheduler_addressINNER JOIN sys.dm_os_tasks AS [dot] ON dot.task_address=dow.task_addressINNER JOIN sys.dm_exec_requests AS [der] ON [dot].[session_id] = [der].[session_id]INNER JOIN sys.dm_exec_sessions AS [des] ON [der].[session_id] = [des].[session_id]WHERE [des].[is_user_process] = 1 GROUP BY
[dot].[scheduler_id],
[task_state]ORDER BY [task_state],[dot].[scheduler_id]If you liked this post, do like my page on FaceBook