February 23, 2024 at 4:03 am
I am a SS rookie. To me it seems like running a query in parallel whenever possible is a great idea b/c that way more work can be done in the same time. Are there any downsides to running a query in parallel?
February 23, 2024 at 6:08 pm
Yep. Lets say you are doing an update on a table or insert which requires an exclusive lock on the table. Having the query go parallel creates self-blocking as you need to wait for thread 1 to release the lock.
Another scenario you are pulling data from a table that is HUGE and the data is spread out across the disk (assuming HDD here, SSD wouldn't have that big of an issue). Thread 1 asks for data in sector 1 while thread 2 is asking for data in sector 1000000 and thread 3 wants data in sector 2 and so on. The read head on the disk is just thrashing across the drive to find the data you want.
Another scenario - you have 128 cores on the machine dedicated to SQL server and have MAXDOP set to 0 (so any query can use up all 128 cores). You have a stored procedure that is a read only (SELECT only without UPDATE, INSERT, or DELETE, but lots of calculations) called frequently that uses up all 128 cores and takes 2 seconds to complete. You have 100 users call that SP at the exact same time. One of those users needs to wait 200 seconds to get their data. User 1 will say the query is fast (2 seconds to get their data... not ideal, but still pretty quick). User 100 will say you need to tune things as they are not waiting almost 3 minutes to get their data.
Even if the query only uses 1/2 the cores, you still have user 100 waiting 100 seconds for the data. I have found that in a LOT of cases, more cores doesn't mean faster results. SOMETIMES (frequently) the bottleneck isn't the CPU and if the bottleneck is something else (disk, network, memory), more threads isn't going to make your query better and can make things worse.
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.
February 23, 2024 at 8:58 pm
I am a SS rookie. To me it seems like running a query in parallel whenever possible is a great idea b/c that way more work can be done in the same time. Are there any downsides to running a query in parallel?
To summarize a bit of personal experience...
Here are some articles on what can prevent parallelism. I've actually verified most of these as actually being true.
https://www.brentozar.com/?s=scalar+functions
https://www.brentozar.com/archive/2020/11/how-scalar-user-defined-functions-slow-down-queries/
https://www.brentozar.com/archive/2020/10/using-triggers-to-replace-scalar-udfs-on-computed-columns/
https://www.brentozar.com/archive/2018/02/using-noexpand-get-parallelism-scalar-udfs-indexed-views/
--Jeff Moden
Change is inevitable... Change for the better is not.
February 24, 2024 at 4:58 am
thank you everyone. What recommended settings for parallelism should I set SS to? Clearly the defaults are not recommended.
February 24, 2024 at 5:11 am
thank you everyone. What recommended settings for parallelism should I set SS to? Clearly the defaults are not recommended.
If you read the text in my post, I tell you.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 26, 2024 at 7:14 pm
To add to this, settings for parallelism are not some "magic" number that can be applied across any environment. If it could be recommended with little to no information, then Microsoft could bake it into the SQL engine to pick good values during install time. There are a lot of factors that come into play when setting up MAXDOP and your cost threshold for parallelism. There are some cases where MAXDOP of 0 may be the correct value or even a value of 1 could be correct. Cost threshold last I heard, the community best practice was to set it to 50 initially and adjust as needed. And even after you get it set up correctly, there may be cases where you have a query that goes parallel and shouldn't OR should go parallel and doesn't and you need to add query hints.
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply