question

Newbie 1 avatar image
Newbie 1 asked

MAXDOP option and Degree of Parallelism in SQL SERVER

I came across the MAXDOP option term recently. It is a new term for me and I made a google search and found this article. But to be honest I could not understand it . Also they are talking about some parallelism and may be these two are interlinked in some way. In simple terms but informative way, can anybody please share some knowledge on both the topic and in which situation should we use it?

Thanks

sql-server-2005
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Magnus Ahlkvist avatar image
Magnus Ahlkvist answered

When a query is run, SQL Server can create a query plan that is executed on more than one processor. This is what query parallellism is about. Configuring the MAXDOP option in the server limits the number of CPUs that can be used in a query plan.

This option does NOT limit the number of CPUs that SQL Server as such is using (for example due to license limitations). It only limits the number of CPUs that SQL Server will use to run a single execution plan.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
I would +1 this if you replaced the word 'CPU' with 'Thread'...
0 Likes 0 ·
Magnus Ahlkvist avatar image Magnus Ahlkvist commented ·
Isn't "thread" and "CPU" in the parallellism in SQL Server effectively the same thing? Will SQL Server ever create more threads than it can distribute on different CPU:s?
0 Likes 0 ·
Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
Yes, it certainly would. Especially with HyperThreading CPUs...
0 Likes 0 ·
Magnus Ahlkvist avatar image Magnus Ahlkvist commented ·
Ok, point taken with hyper threading. Although to me, as a developer trying to stay as far away from hardware as possible, if it looks like four CPU:s, it is four CPU:s, regardless of actual hardware :)
0 Likes 0 ·
Grant Fritchey avatar image
Grant Fritchey answered

When you have multiple processors in a computer, SQL Server can take advantage of using more than one processor by creating multiple threads, threads are how the operating system takes advantage of multiple processors by using different execution paths. There are two general factors that affect whether or not a parallel plan is generated. The first is whether or not you have enabled multiple processor use. By default the server is set to zero, which means it will use all processors available, but you can limit it to only using one or some sub-set of processors (there are other options there as well, but I won't get into them at this point). Second, you can set the cost threshold for parallelism. This uses the estimated cost of an execution plan as part of a series of calculations that determine when to use multiple processors, if available. The default for this value is 5, and in my opinion, WAY too low. I usually set it to somewhere between 25-35, depending on the system and the queries being run against it.

MAXDOP is a query hint that will allow you to control, for a given query, how parallelism is applied. It is a useful hint when you have a query that is hitting parallelism, but not benefiting from it. However, most of the time it is used incorrectly when the cost threshold for parallelism should be adjusted upwards instead. Seting the MAXDOP to 1 will prevent the query for using multiple processors through multiple threads.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Leo avatar image Leo commented ·
Hi Grant, I have new server installed last month -Dell Poweredge R710, checked for Cost Threshold for parallelism which is set to 5. Shall I change it to 35? Do you think that will make better performance? Here is my server spec - Intel Xeon E5520 2.7GHz x 2, 24GB Memory
0 Likes 0 ·
Blackhawk-17 avatar image Blackhawk-17 commented ·
@Leo - you will have to experiment with your query load (buy Grant's book to see what to look for) and decide what is acceptable across your implementation.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.