Thursday, November 1, 2007

SQL:Running, runnable, and suspended status

If you have only one CPU, only one process can run at a time. The current running process has running status. All processes waiting for CPU have the runnable status. When the CPU runs a process and finds out the required resource, e.g. data page, is not available at the moment, the process will be moved to wait list and its status will be SUSPENDED.


SLEEPING status
A session status of 'Sleeping' indicates SQL Server is waiting for the next SQL Server command.

The sys.dm_os_waiting_tasks DMV lists the data from the current wait list.

The sys.dm_exec_requests DMV lists the data from current runnable queue.

How do we use sys.dm_os_waiting_tasks and sys.dm_exec_requests?

The sys.dm_os_wait_stats contains the wait statistics since the start of SQL Server or since you run DBCC SQLPERF('sys.dm.os_wait_stats',CLEAR). As you see from above diagram, anytime a session (SPID) waits for a resource, the session will be moved into wait list queue. The wait_time_ms is the Total wait time for this wait type in milliseconds. This time is inclusive of signal_wait_time_ms in sys.dm_exec_requests.

So, the resource wait time=wait_time_ms - signal_wait_time_ms

The key question is not the length of the runnable queue but rather how much time is spent waiting for CPU compared to the resource waits of the wait list.

If signal_wait_time_ms/wait_time_ms is less 25%, you could conclude that the CPU pressure has little pressure because the resource waits cost a lot.

Wait and Queue

From an application perspective, the application waits for resources and waits for its request to be completed. Waits are represented by SQL Server wait statistics.

From a resource perspective, its queue measues its utilization. Performance Monitor objects and counters describe the queue.