SQL SERVER – Threads Not Counted for Max Worker Threads

I am often surprised how I must evolve to support my clients at Comprehensive Database Performance Health Check. I had a very interesting situation where I had to find all the threads which are not counted for max worker threads in SQL Server. Let us see the script today.

Here is the script:

SELECT r.command,
w.last_wait_type,
COUNT(*) TotalCount
FROM sys.dm_exec_sessions s
INNER JOIN sys.dm_exec_requests r ON s.session_id = r.session_id
INNER JOIN sys.dm_os_tasks t ON r.task_address = t.task_address
INNER JOIN sys.dm_os_workers w ON t.worker_address = w.worker_address
WHERE s.is_user_process = 0
GROUP BY r.command,
w.last_wait_type
ORDER BY TotalCount DESC

When you run the script above it will list all the commands and wait for types with the thread counts. However, this thread count is not counted against your Max Worker Threads as they are primarily system processes and not user processes.

SQL SERVER - Threads Not Counted for Max Worker Threads threads-800x425

Remember it is not always the case when your user queries takes up the resources in the SQL Server, there have been cases when system processes also taking the critical resources away from your system.

Here are my few recent videos and I would like to know what is your feedback about them. Do not forget to subscribe SQL in Sixty Seconds series.

Reference: Pinal Dave (http://blog.SQLAuthority.com)

CPU Scheduler, CPU Threads, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Types of Triggers
Next Post
SQL SERVER – Find Total Sessions by Database

Related Posts

Leave a Reply