Solved

Slow Running Stored Procedure

Posted on 2014-01-29
3
515 Views
Last Modified: 2014-01-30
Hi,

I have an issue where by a particular SP when executed, takes more than 5 minutes to execute on a Production system. Interestingly, the same SP when executed in an UAT environment takes less than 5 seconds to complete.

The servers are similar in terms of set-up/infrastructure. I've inspected the execution plan for both and can see that Production system uses Parallelism to execute the query, UAT doesn't.

Instance settings for Parallelism on both servers are the same (default).

Just to add on the server where I'm seeing the issue a high number of waits on CXPACKET are seen, where there all in a 'suspended' state, I have queried sys.dm_os_waiting_tasks for the  session_id that's executing the SP (that has the CXPACKET waits), to try and establish the non wait_type of CXPACKET, to see what is being waited on, but this returns nothing.

Could someone suggest please what the probable causes could be here? as to why I'm seeing such a high number of CXPACKETS in a suspended state? I can't see what they're waiting on!

Thanks.
0
Comment
Question by:rdbconcepts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39818659
CXPACKET is a wait type used by SQL Server when it is waiting for the other thread to complete....

That is if an update query runs in a parallel mode and let us say it spawns 8 threads, and 5 threads are completed and 3 are not, then the 5 which are completed will be put in CXPACKET wait status and the running will be in suspended state, once the other 3 also gets completed, these will move out of suspended state.


Solution
the issue here is exactly what you observed the parallelism...
Before following the below steps, try to update your statistics on all your tables (or atleast the tables involved) and check if there is a different. You can use the below command to do that

sp_updateStats

Open in new window


Although experts recomend not to do the below stuff as a quick fix check the below options

Run this in your UAT environment

USE <your Database> ;
GO 
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
EXEC sp_configure 'max degree of parallelism';

Open in new window


See what is the output for the last statement, most probably it will be 1 (or let us say it is 1 for now)

then execute the below statement in your prod

USE <your Database> ;
GO 
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
EXEC sp_configure 'max degree of parallelism',1;

Open in new window


The above code, tells SQL to use only one thread for the query processing, although this is not recomended this might solve your issue where there is no sync between QA performance and prod performance
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 39818873
First, try that specific query in production with no parallelism in the query, like so:

SELECT ...
...rest of query...
OPTION ( MAXDOP 1 )

If that runs much better, then you need to decide which type of change you want to make to the production parallelism setting:

1) Use the hint to change only that one query
2) Raise the threshold for SQL to use parallelism -- this is the "standard" first step for DBAs
3) Reduce MAXDOP for the entire instance.  This is normally the last choice :EXCEPTION: MAXDOP should always be set to no more than the number of physical processors.  With less than 8 total processors, MAXDOP is often set to use them all.  With 8 or more physical processors, you typically leave one or two out (depending on the level of other CPU activity on the server), so MAXDOP would then be 6 or 7, or for 16 processors, 14 or 15, etc..
0
 
LVL 35

Expert Comment

by:David Todd
ID: 39819399
Hi,

Is test running Developer Edition and Production running Standard Edition?

Regards
  David
0

Featured Post

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS 2013 - Overlapping reports 2 39
get_systemdrive info from tsql? 1 23
How to keep a record with the highest value 3 40
Need to trim my database size 9 24
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question