Reserved threads and Used threads in parallelism

HI Friends,

We know about parallelism in SQL Server i.e. SQL Server uses multiple threads for the processing of a request to make it faster.  Two main important settings for the decision of going with parallelism are:

MAXDOP: Maximum degree of parallelism, This value represents, how many threads can be used for parallel processing.

The Cost threshold for parallelism: if any estimated query plan cost crossed this value, then the SQL Server optimizer will try to make that plan parallel.

Now come back to our topic, Reserved threads and Used threads in parallelism. Let’s say I have submitted a query to the SQL Server and estimated cost of this query has been crossed the value of cost threshold for parallelism. SQL Server has been decided to execute that query using parallelism. In my test system, MAXDOP is set to default. That means SQL Server can use all the processors for parallel operations, assign to it i.e. 4. I have set the value 0 for cost threshold for parallelism just to use the parallelism for every query (keep in mind this is just for demo). By default, SQL Server uses threads to perform its task and these tasks run on schedulers.

Like many other resources, SQL Server also reserved the number of threads. Let me show you the execution plan of below query on Adventure Works 2014 Database :

SELECT [SalesOrderID]
      ,[SalesOrderDetailID]
      ,[CarrierTrackingNumber]
      ,[OrderQty]
      ,[ProductID]
      ,[SpecialOfferID]
      ,[UnitPrice]
      ,[UnitPriceDiscount]
      ,[LineTotal]
      ,[rowguid]
      ,[ModifiedDate]
  FROM [AdventureWorks2014].[Sales].[SalesOrderDetail]
  ORDER BY ModifiedDate DESC

Plan1

Now you can just right click on the select node and go to the properties:

Properties1

   

In the above Properties, you can see that SQL Server uses Degree of Parallelism to 2. Also count the branch for this execution which is 1. Number of reserved threads and used threads are 2.

Keep in mind that number of reserved or used threads are not always equal to the value of MAXDOP for the query. Let me show you:

Select SOD.SalesOrderID, SOD.UnitPrice, SOD.LineTotal,
SOH.TotalDue, SOH.DueDate, SOH.OrderDate
from [Sales].[SalesOrderDetail] SOD
inner join [Sales].[SalesOrderHeader] SOH
on sod.SalesOrderID=SOH.SalesOrderID
ORDER BY SOH.TotalDue DESC

Plan2

Now you can just right click on the select node and go to the properties:

Properties2

In the above Properties, you can see that SQL Server uses Degree of Parallelism 4. Here branch count for this execution is 2. Number of reserved threads and used threads are 8.

HAPPY LEARNING!

Regards:

Prince Kumar Rastogi

Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook

Follow Prince Rastogi on Twitter | Follow Prince Rastogi on FaceBook

   

About Prince Rastogi

Prince Rastogi is working as Database Administrator at Elephant Insurance, Richmond. He is having more than 8 years of experience and worked in ERP Domain, Wealth Management Domain. Currently he is working in Insurance domain. In the starting of his career he was working on SQL Server, Internet Information Server and Visual Source Safe. He is post graduate in Computer Science. Prince is ITIL certified professional. Prince likes to explore technical things for Database World and Writing Blogs. He is Technical Editor and Blogger at SQLServerGeeks.com. He is a regular speaker at DataPlatformDay events in Delhi NCR. He has also presented some in depth sessions about SQL Server in SQL Server Conferences in Bangalore.

View all posts by Prince Rastogi →

Leave a Reply

Your email address will not be published.