SQLWindowsHow to Resolve Max Worker Threads issues in SQL Server June 16, 201618995 views0Share By IG ShareTable of ContentsNote: If you buy something from our links, we might earn a commission. See our disclosure statement. How to Resolve Max Worker Threads issues in SQL ServerHow to change the Max Worker Threads count using T-SQLMax Worker Threads Best Practices for Database Mirroring and Always On Availability GroupsHow to Calculate MWT Count?How to Resolve Max Worker Threads issues in SQL ServerBefore we discuss about performance issues related to Max Worker Threads (MWT) let’s understand what MWT actually does. MWT are worker threads available for SQL Server and using the native Windows threads SQL Server simultaneously handles multiple tasks in parallel. For example, Database checkpoints, network layer processes, handling transaction processing etc. The default value is 0. The 0 value allows SQL Server to dynamically spawn threads based on server resources. This works for the majority of the SQL Server deployment worldwide. To improve performance, sometimes increasing the MWT value manually helps. In this post, I am going to talk about how to resolve max worker threads issues in SQL Server.You will only run out of MWT when the SQL Server is very busy, high user concurrency and additional features like SQL Server Always On, Replication Services are enabled. Based on SQL Server versions (32 bit or 64 bit) and processor cores, a pool of worker threads are spawned by SQL Server to service user requests. Here is a quick look at the hard numbers.CPU Core CountOlder 32 bit ServersLatest 64 bit ServersUp-to 4 processors256512Octa-Core 8 processors28857616 processors35270432 processors48096064 processors7361472128 processors42244480256 processors83208576The MWT Configuration option excludes threads used for Always On Availability Groups and Database Mirroring.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;How to change the Max Worker Threads count using T-SQLUSE AdventureWorks2016 ; GO EXEC sp_configure 'show advanced options', 1; GO RECONFIGURE ; GO EXEC sp_configure 'max worker threads', 1000 ; GO RECONFIGURE; GOSometimes, reducing the Worker Thread count improves performanceMax Worker Threads Best Practices for Database Mirroring and Always On Availability GroupsTo Avoid MWT exhaustion, do not create more than 10 Availability Groups and 100 Databases. This means, 10 DB’s per Availability group. This is a recommendation and not a hard limit.If there is a MWT enhaustion, Add Additional CPU’s or Virtual CPU’s (In case of Virtual Machines) in order to increase MWT count. See the above table for reference.Creating another instance on the same server to improve MWT will not increase performance.Too much Database Consolidation with Databases running Mirroring and Availability Groups can cause MWT exhaustion.Calculate the Max MWT and test the system extensively before implementing Always on AG.How to Calculate MWT Count?MWT = {512 + ((Number of CPU Cores - 4) * 16)} = ResultHow to Calculate Max Worker Thread Usageselect scheduler_id,current_tasks_count, current_workers_count,active_workers_count,work_queue_count from sys.dm_os_schedulers where status = ‘Visible Online’Breakdown of which System Task is using MWT Threadsselect is_preemptive,state,last_wait_type,count(*) as NumWorkers from sys.dm_os_workers Group by state,last_wait_type,is_preemptive order by count(*) descOfficial Online Resources from MicrosoftLean about max worker threads OptionLearn about SQL Server Always On Restrictions Affiliate Disclosure: Faceofit.com is a participant in the Amazon Services LLC Associates Program. As an Amazon Associate we earn from qualifying purchases. Share What's your reaction? Excited 1 Happy 0 In Love 0 Not Sure 0 Silly 0
SQLSQL Server Disk Configuration SAN SSD and Partitioning Best PracticesSQL Server Disk configuration settings are one of the most important aspects of SQL Server ...
SQLSystem Center Deployment Requirements and Restrictions for SQL ServerSystem Center contains a suite of products and enterprises who have investments in them deploy ...
SQLHow To License Your SQL Server on Google CloudIn my previous post, we deployed SQL Server 2016 on a Windows Server 2012 R2 Operating ...
Enterprise TechHow to Run Microsoft SQL Server 2016 on Google Cloud Step by StepGoogle Cloud Services recently added Microsoft SQL Server to its offerings. Google’s move is primarily ...