Gig XP

Fixing SQL Server Max Worker Threads: error: 35217, severity: 16, state: 1

Fixing SQL Server Max Worker Threads

If you try fixing SQL Server Max Worker Threads for errors such asThe thread pool for AlwaysOn Availability Groups was unable to start a new worker thread.” then we have some recommendations for you. The error looks like something given below:

Error: The thread pool for AlwaysOn Availability Groups was unable to start a new worker thread.”

Fixing SQL Server Max Worker Threads

Typically, the easiest shortcut to solve this problem is by increasing the number of CPU cores in your operating environment. If you are running a VM (Virtual Machine), this can be achieved quickly, provided you have the available resources. But, it would be better to understand why this occurs and what are the limitations for such scenarios.

Thread Usage by Availability Groups

Always On availability groups (AG) has the following requirements for worker threads:

Threads are always shared on an on-demand basis, as follows:

Note to Self:

Databases are determined to go single-threaded based on their ascending database ID. As such, the database creation order should be counted for SQL Server instances that host more availability group databases than the available worker threads. For example, on a system with 64 or more CPU cores, all databases starting with the 7th database that joined the availability group will be in serial redo mode irrespective of the actual redo workload for each database. Databases that require parallel redo should be added to the availability group first.

For more information, see Worker Pool Usage for Availability Groups Enabled Databases

Also Read: SQL Server Always On Max Worker Threads Restrictions

Here is a quick look at the fixed numbers.

CPU Core Count Older 32 bit Servers Latest 64 bit Servers
Up-to 4 processors 256 512
Octa-Core 8 processors 288 576
16 processors 352 704
32 processors 480 960
64 processors 736 1472
128 processors 4224 4480
256 processors 8320 8576

How to change the Max Worker Threads count using T-SQL

USE AdventureWorks2016 ; 

GO 

EXEC sp_configure 'show advanced options', 1; 

GO 

RECONFIGURE ; 

GO 

EXEC sp_configure 'max worker threads', 1000 ; 

GO 

RECONFIGURE; 

GO

Use the following Query to find out which System Tasks have caused additional worker threads to be spawned:

SELECT 

s.session_id, 

r.command, 

r.status, 

r.wait_type, 

r.scheduler_id, 

w.worker_address, 

w.is_preemptive, 

w.state, 

t.task_state, 

t.session_id, 

t.exec_context_id, 

t.request_id 

FROM sys.dm_exec_sessions AS s 

INNER JOIN sys.dm_exec_requests AS r 

    ON s.session_id = r.session_id 

INNER JOIN sys.dm_os_tasks AS t 

    ON r.task_address = t.task_address 

INNER JOIN sys.dm_os_workers AS w 

    ON t.worker_address = w.worker_address 

WHERE s.is_user_process = 0;

Conclusion

Typically, you will face difficulties with worker threads on SQL Server when you do not have enough CPU cores to handle the load. In these scenarios, you will need to increase the CPU cores to address the problem.

Questions or suggestions are welcome in the comments section below. Thanks!