Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Query causing CPU Spikes on SQL Server 2008 r2


SQL Query causing CPU Spikes on SQL Server 2008 r2

Author
Message
APA0876
APA0876
SSC-Enthusiastic
SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)

Group: General Forum Members
Points: 150 Visits: 400
Hi,
I have a curious case here: there is a SQL Query that is causing 90% of CPU on one of the SQL servers also it run in 14 seconds, on other server with similar specs the query executes in less than a second and no cpu spikes also the server configurations are the same:
What can be happening here?

select distinct
spid = cast(p.spid as int),
program = p.program_name,
host = p.hostname,
login = p.loginame,
databasename = replace(db_name(ISNULL(convert(int,l.rsc_dbid),-1)),char(39),char(39)+char(39)),
object = ISNULL(l.rsc_objid,-1),
request_mode = substring (v.name, 1, 8),
blockedwait = b.waittime,
inputbuffer = case when isnull(p.net_address, '') = '' then null else (select case when dmv.objectid is null then left(max(text),4000) else null end from sys.dm_exec_sql_text(p.sql_handle) dmv group by dmv.objectid) end,
starttime = dateadd(ss,cast(b.waittime as float)/1000 * -1,getutcdate())
from
master..sysprocesses p (nolock)
left join master..sysprocesses b (nolock)
on p.spid = b.blocked
left outer join master..syslockinfo l (nolock)
on b.spid = l.req_spid
and l.req_status in (2,3)
left join master.dbo.spt_values v
on convert(int,l.[req_mode]) + 1 = v.number
where
p.blocked = 0
and p.program_name not like 'SQLAgent%'
and p.program_name not in ('SQL PerfMon')

and b.blocked <> 0
and b.waittime > 166000
and v.type = 'L'

Thanks for your help
Vedran Kesegic
Vedran Kesegic
Old Hand
Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)

Group: General Forum Members
Points: 382 Visits: 1255
Check if actual execution plans are different. Are those virtual machines?

_____________________________________________________
Microsoft Certified Master: SQL Server 2008
XDetails Addin - for SQL Developers
blog.sqlxdetails.com - Transaction log myths

SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21101 Visits: 18259
Please provide the actual execution plan for both servers for the query.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

APA0876
APA0876
SSC-Enthusiastic
SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)

Group: General Forum Members
Points: 150 Visits: 400
How can I send the execution plan on an xml format?
Thanks
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21101 Visits: 18259
See the first link in my signature. The instructions for posting the exec plan are there.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Bhuvnesh
Bhuvnesh
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2928 Visits: 4076
APA0876 (1/10/2013)
there is a SQL Query that is causing 90% of CPU on one of the SQL servers also it run in 14 seconds, on other server with similar specs the query executes in less than a second and no cpu spikes also the server configurations are the same:


did you run the query at the same time?
are both(or other servers ) returning same records for this query ?
do both servers have same load (like job or background prcosses)
do they have same equal no of connections (at the time of query) ?

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
APA0876
APA0876
SSC-Enthusiastic
SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)

Group: General Forum Members
Points: 150 Visits: 400
Bhuvnesh (1/10/2013)
APA0876 (1/10/2013)
there is a SQL Query that is causing 90% of CPU on one of the SQL servers also it run in 14 seconds, on other server with similar specs the query executes in less than a second and no cpu spikes also the server configurations are the same:


did you run the query at the same time?
are both(or other servers ) returning same records for this query ?
do both servers have same load (like job or background prcosses)
do they have same equal no of connections (at the time of query) ?


Yes I run the query at the same time
Yes 0 records
different Load the server with the spikes is 20 % avg CPU and the other 5% Avg CPU
On the server having the CPU spike there are 1700 connections and the other 10 connections.

But what should I do, this query is exected every 6 minutes because is part of a diagnostic Tool.

Thanks
Ailyn
anthony.green
anthony.green
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6102 Visits: 6078
I would completly re-write it all, for one all the tables used are depreciated and are in the product for SQL 2000 compatability only, you really should be using the DMV's.



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21101 Visits: 18259
APA0876 (1/11/2013)
Bhuvnesh (1/10/2013)
APA0876 (1/10/2013)
there is a SQL Query that is causing 90% of CPU on one of the SQL servers also it run in 14 seconds, on other server with similar specs the query executes in less than a second and no cpu spikes also the server configurations are the same:


did you run the query at the same time?
are both(or other servers ) returning same records for this query ?
do both servers have same load (like job or background prcosses)
do they have same equal no of connections (at the time of query) ?


Yes I run the query at the same time
Yes 0 records
different Load the server with the spikes is 20 % avg CPU and the other 5% Avg CPU
On the server having the CPU spike there are 1700 connections and the other 10 connections.

But what should I do, this query is exected every 6 minutes because is part of a diagnostic Tool.

Thanks
Ailyn


Post the execution plans so we can better see what is happening and provide better answers.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

APA0876
APA0876
SSC-Enthusiastic
SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)

Group: General Forum Members
Points: 150 Visits: 400
APA0876 (1/10/2013)
How can I send the execution plan on an xml format?
Thanks


I posted two SQLPlans one for the server with the spike and the other sql for server that is OK
Attachments
ServerWSpike.sqlplan (18 views, 75.00 KB)
ServerOK.sqlplan (4 views, 72.00 KB)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search