Tuesday 5 February 2013

About the Max worker Threads


MAX WORKER THREADS

Use the max worker threads option to configure the number of worker threads available to Microsoft SQL Server processes.

Purpose of Max worker threads option:
Thread pooling helps optimize performance when large numbers of clients are connected to the server. Usually, a separate operating system thread is created for each query request. However, with hundreds of connections to the server, using one thread per query request can consume large amounts of system resources. The max worker threads option enables SQL Server to create a pool of worker threads to service a larger number of query request, which improves performance.

Calculating Max worker Threads:
The default value for max worker threads, 0, allows SQL Server to automatically configure the number of worker threads at startup. This setting is best for most systems; however, depending on your system configuration, setting max worker threads to a specific value sometimes improves performance.
The max worker threads is based on the number of processors…with help of the below formula we can calculate the max worker threads.
For x86 (32-bit) upto 4 logical processors max worker threads = 256
For x86 (32-bit) more than 4 logical processors max worker threads = 256 + ((# Procs – 4) * 8)
For x64 (64-bit) upto 4 logical processors max worker threads = 512
For x64 (64-bit) more than 4 logical processors max worker threads = 512+ ((# Procs – 4) * 16)
With help of the below DMV we can find the max workers threads count:

Select max_workers_count from sys.dm_os_sys_info

As per the Micro soft 1024 as the maximum for 32 bit SQL Server.
When the actual number of query request is less than the amount set in max worker threads, one thread handles each query request. However, if the actual number of query request exceeds the amount set in max worker threads, SQL Server pools the worker threads so that the next available worker thread can handle the request.
Upgrading from sql server 2000:
The default setting of max worker threads in SQL Server 2000 was 255. Upgrading an instance of the SQL Server 2000 Database Engine to a newer version retains the configuration value for max worker threads. When upgrading, we recommend changing the new instance max worker threads value to 0, to allow the Database Engine to calculate the optimal number of threads.
How to configure the max worker threads:
From SSMS also we can configure the max worker threads…
Go to Server Node ----> Right Click and Select Property ----> Select Process and modify setting under Worker Threads.


The max worker threads option is an advanced option. If you are using the sp_configure system stored procedure to change the setting, you can change max worker threads only when show advanced options is set to 1. The system must be restarted in order for the new setting to take effect.
Note: When all worker threads are active with long running queries, SQL Server may appear unresponsive until a worker thread completes and becomes available. Though not a defect, this can sometimes be undesirable. If a process appears to be unresponsive and no new queries can be processed, then connect to SQL Server using the dedicated administrator connection (DAC), and kill the process. To prevent this, increase the number of max worker threads.

With help of the below DBCC we can find the num of tasks, num of works, and active works etc…
DBCC SQLPERF(UMSSTATS)
The following link having good example for Threadpool wait type…because of the lack of worker thread we get the threadpool wait type…don't forget to check the below link...


Note: I gather the above information from different internet links…


JHAPPY LEARNINGJ

How to connect the sql server through Dedicated Admin Connection and which situation we connect the sql through DAC...?


How to: Use the Dedicated Administrator Connection with SQL Server Management Studio

Microsoft SQL Server provides a dedicated administrator connection (DAC). The DAC allows an administrator to access a running instance of SQL Server Database Engine to troubleshoot problems on the server—even when the server is unresponsive to other client connections. The DAC is available through the sqlcmd utility and SQL Server Management Studio. The connection is only allowed from a client running on the server. No network connections are permitted.

To use SQL Server Management Studio with the DAC, connect to an instance of the SQL Server Database Engine with Query Editor by typing ADMIN: before the server name. Object Explorer cannot connect using the DAC.

To connect to a server using the DAC

  1. In SQL Server Management Studio, with no other DACs open, on the toolbar, click Database Engine Query.
  2. In the Connect to Database Engine dialog box, in the Server name box, type ADMIN: followed by the name of the server instance. For example, to connect to a server instance named ACCT\PAYABLE, type ADMIN:ACCT\PAYABLE.
  3. Complete the Authentication section, providing credentials for a member of the sysadmin group, and then click Connect.

The connection is made.

If the DAC is already in use, the connection will fail with an error indicating it cannot connect.

When the sql server is unresponsive:

The following are the situations

1)      When the long running queries are running and assume these queries are utilizing the all available works threads…means there is no work thread for new query and new connection…this time the sql server is in unresponsive stats…

When the works threads are available the sql server accepts the new connection…

In this situation we can connect the sql server through DAC and kill the unimportant long running queries and free the works threads…

2)      Assume we didn’t set the minimum and maximum sql server memory…in this situations the sql server have the chance to utilizing all available memory… as per the mechanism the sql server release the unused memory to the os when the os requests…but in the following combination of the os and sql server it won't release the unused memory to windows(os)…

2005 sql server running on the window server 2003…the sql server won’t release the occupied memory to window when it’s request for some memory…in this situation the windows forcefully get the memory from the sql server…in this position the sql server won’t accept the new connection…

In the above situation we need to restart the sql server or connect the sql server through DAC and configure the min and max memory to the sql server…
NOTE: I gather above information from multiple internet links...

J HAPPY LEARING J