How Much Work Each Processor (CPU) is Doing in SQL Server? – Interview Question of the Week #178

Question: How much work is queued for each CPU in SQL Server? Look at visible online schedulers.

Loom stations have different amounts of waiting work in their baskets

I hadn’t encountered this question in an interview. A client asked it during a Comprehensive Database Performance Health Check. CPU usage stayed high despite more than 56 active processors.

The client wanted to know where work was waiting. SQL Server’s scheduler DMV helps answer that narrower question. It doesn’t report a Windows CPU utilization percentage.

SELECT scheduler_id, cpu_id, parent_node_id,
       current_tasks_count, runnable_tasks_count, work_queue_count
FROM sys.dm_os_schedulers
WHERE status = N'VISIBLE ONLINE'
ORDER BY scheduler_id;

The status filter selects schedulers available for ordinary user work. The older scheduler_id < 255 shortcut can omit schedulers on larger systems. Use cpu_id and parent_node_id to interpret the logical processor and node association.

ColumnWhat it tells you
current_tasks_countTasks associated with the scheduler, including tasks awaiting workers and tasks assigned to workers.
runnable_tasks_countWorkers with assigned tasks waiting for their turn on the runnable queue.
work_queue_countTasks waiting for a worker to pick them up.
Original eight-scheduler sample with zero runnable and work queues
My original sample had zero runnable and work queues at capture time. Those rows show no backlog in those queues at that moment.

Take more than one sample

A single high count can disappear before your next query. Sample during the problem and look for a persistent pattern. Growing runnable queues suggest competition for scheduler time; pending work queues call for a worker-availability investigation.

I’d also compare waits, active requests and operating-system CPU measurements. More processors alone won’t fix an expensive query or blocked work. This DMV tells us where to investigate, not which setting to change.

SQL Server 2022 and later require VIEW SERVER PERFORMANCE STATE for this view. Earlier versions require VIEW SERVER STATE. Review access with your administrator rather than granting broad server privileges.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL CPU, SQL DMV, SQL Scripts, SQL Server
Previous Post
How to Find Cardinality or Uniqueness for any Column? – Interview Question of the Week #177
Next Post
How to Find Service Account for SQL Server and SQL Server Agent? – Interview Question of the Week #179

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.