SQL SERVER – Reducing CXPACKET Wait Stats for High Transactional Database
Posted
by pinaldave
on SQL Authority
See other posts from SQL Authority
or by pinaldave
Published on Sat, 13 Nov 2010 01:30:53 +0000
Indexed on
2010/12/06
16:58 UTC
Read the original article
Hit count: 834
sql
|SQL Authority
|SQL Optimization
|SQL Performance
|SQL Query
|SQL Server
|SQL Tips and Tricks
|SQL White Papers
|SQLAuthority News
|T SQL
|Technology
While engaging in a performance tuning consultation for a client, a situation occurred where they were facing a lot of CXPACKET Waits Stats. The client asked me if I could help them reduce this huge number of wait stats. I usually receive this kind of request from other client as well, but the important thing to understand is whether this question has any merits or benefits, or not.
Before we continue the resolution, let us understand what CXPACKET Wait Stats are.
The official definition suggests that CXPACKET Wait Stats occurs when trying to synchronize the query processor exchange iterator. You may consider lowering the degree of parallelism if a conflict concerning this wait type develops into a problem. (from BOL)
In simpler words, when a parallel operation is created for SQL Query, there are multiple threads for a single query. Each query deals with a different set of the data (or rows). Due to some reasons, one or more of the threads lag behind, creating the CXPACKET Wait Stat. Threads which came first have to wait for the slower thread to finish. The Wait by a specific completed thread is called CXPACKET Wait Stat. Note that CXPACKET Wait is done by completed thread and not the one which are unfinished.
“Note that not all the CXPACKET wait types are bad. You might experience a case when it totally makes sense. There might also be cases when this is also unavoidable. If you remove this particular wait type for any query, then that query may run slower because the parallel operations are disabled for the query.”
Now let us see what the best practices to reduce the CXPACKET Wait Stats are.
The suggestions, with which you will find that if you search online through the browser, would play a major role as and might be asked about their jobs In addition, might tell you that you should set ‘maximum degree of parallelism’ to 1. I do agree with these suggestions, too; however, I think this is not the final resolutions. As soon as you set your entire query to run on single CPU, you will get a very bad performance from the queries which are actually performing okay when using parallelism.
The best suggestion to this is that you set ‘the maximum degree of parallelism’ to a lower number or 1 (be very careful with this – it can create more problems) but tune the queries which can be benefited from multiple CPU’s.
You can use query hint OPTION (MAXDOP 0) to run the server to use parallelism.
Here is the two-quick script which helps to resolve these issues:
Change MAXDOP at Server Level
EXEC sys.sp_configure N'max degree of parallelism', N'1'
GO
RECONFIGURE WITH OVERRIDE
GO
Run Query with all the CPU (using parallelism)
USE AdventureWorks
GO
SELECT *
FROM Sales.SalesOrderDetail
ORDER BY ProductID
OPTION (MAXDOP 0)
GO
Below is the blog post which will help you to find all the parallel query in your server.
SQL SERVER – Find Queries using Parallelism from Cached Plan
Please note running Queries in single CPU may worsen your performance and it is not recommended at all. Infect this can be very bad advise.
I strongly suggest that you identify the queries which are offending and tune them instead of following any other suggestions.
Reference: Pinal Dave (http://blog.sqlauthority.com)
Filed under: SQL, SQL Authority, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, SQL White Papers, SQLAuthority News, T SQL, Technology
© SQL Authority or respective owner