Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Stored Proc and performance Expand / Collapse
Author
Message
Posted Wednesday, January 16, 2013 9:13 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, December 11, 2014 11:23 AM
Points: 337, Visits: 598
Is there any SQL that can be added to a Stored Proc to track if there was any blocking of its SQL, or for that matter explain the example below?

I am tasked with explaining, and if possible fixing, jobs that sometimes run more than twice their normal run times. A good example is a program that almost always runs in less than one min, but this morning it took 4 1/2 hours to run. This created problems since our data was not fully loaded when folks started using the application.

Thanks
Post #1407911
Posted Wednesday, January 16, 2013 5:47 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 9:53 PM
Points: 3,438, Visits: 5,390
You could try turning on the deadlocks trace flag:

DBCC TRACEON (1222, -1)


And then checking the log to see if it reports deadlocks during the period the job is running.



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1408111
Posted Thursday, January 17, 2013 2:03 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 2:53 AM
Points: 1,101, Visits: 5,290
dwilliscp (1/16/2013)
Is there any SQL that can be added to a Stored Proc to track if there was any blocking of its SQL, or for that matter explain the example below?

I am tasked with explaining, and if possible fixing, jobs that sometimes run more than twice their normal run times. A good example is a program that almost always runs in less than one min, but this morning it took 4 1/2 hours to run. This created problems since our data was not fully loaded when folks started using the application.

Thanks

No. There is no SQL that can be added to a Stored Proc to track if there was any blocking of its SQL.

But you can create another job to periodically check for the blocking and send you alert if there is any blocking.
You can start here:
select * from sys.dm_exec_requests where blocking_session > 0

Note that your job might have taken 4.5 hrs due to some other reason also (not necessary due to blocking).

There was no deadlock. Deadlock would fail the job.
Post #1408221
Posted Thursday, January 17, 2013 5:23 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 9:53 PM
Points: 3,438, Visits: 5,390
Suresh B. (1/17/2013)

There was no deadlock. Deadlock would fail the job.


Incorrect. SQL Server kills only the transaction that costs the least to rollback, so the competing transaction could have been killed and the SP completed without failure.



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1408357
Posted Thursday, January 17, 2013 8:03 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, December 11, 2014 11:23 AM
Points: 337, Visits: 598
Thanks I will try and see what I get, but not sure that it will show much if I am just checking for deadlocks. All the job (at that step does) is copy records from one table to update a different table. PerfMon did not show anything abnormal (CPU,Mem,Phy IO), so my guess is that a user was in making changes to the forecast and did not file the screen... but that is just a guess. If I am right it would not have created a deadlock, just blocking.
Post #1408435
Posted Thursday, January 17, 2013 5:22 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 9:53 PM
Points: 3,438, Visits: 5,390
dwilliscp (1/17/2013)
Thanks I will try and see what I get, but not sure that it will show much if I am just checking for deadlocks. All the job (at that step does) is copy records from one table to update a different table. PerfMon did not show anything abnormal (CPU,Mem,Phy IO), so my guess is that a user was in making changes to the forecast and did not file the screen... but that is just a guess. If I am right it would not have created a deadlock, just blocking.


Here my experience is a little rough but my understanding is that blocks are a normal process. SQL must block some transactions, allowing others to complete if they've established locks. When a lock is kept and held for too long, the blocked transaction will then be considered in deadlock with it. So that is when SQL Server kicks in to decide which of the transaction processes should be killed.



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1408680
Posted Thursday, January 17, 2013 9:27 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 10:48 AM
Points: 20,857, Visits: 32,877
dwain.c (1/17/2013)
dwilliscp (1/17/2013)
Thanks I will try and see what I get, but not sure that it will show much if I am just checking for deadlocks. All the job (at that step does) is copy records from one table to update a different table. PerfMon did not show anything abnormal (CPU,Mem,Phy IO), so my guess is that a user was in making changes to the forecast and did not file the screen... but that is just a guess. If I am right it would not have created a deadlock, just blocking.


Here my experience is a little rough but my understanding is that blocks are a normal process. SQL must block some transactions, allowing others to complete if they've established locks. When a lock is kept and held for too long, the blocked transaction will then be considered in deadlock with it. So that is when SQL Server kicks in to decide which of the transaction processes should be killed.


Not correct, Dwain. Blocking and Deadlock are two different beasts. A deadlock exists if two processes are are waiting are each waiting for a resource locked by the other process. If a process is simply blocked by another, like an update is waiting for a shared read (not sure of the correct term) to be released to place an exclusive lock to make an update, you may get a time-out, but it isn't deadlocked.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1408704
Posted Thursday, January 17, 2013 9:33 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 9:53 PM
Points: 3,438, Visits: 5,390
Lynn Pettis (1/17/2013)

A deadlock exists if two processes are are waiting are each waiting for a resource locked by the other process.


Easy for you to say.

Like I said, I was a little rough on this myself, so figured someone would come along and correct me.



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1408707
Posted Monday, January 21, 2013 5:11 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, November 5, 2014 11:16 AM
Points: 75, Visits: 622
Any old CICS mainframe programmers here remember calling a deadlock a "deadly embrace"? That wasn't limited to just databases, which were relatively new in my environment (we were still using VSAM), but also the resources that you needed to control.
Post #1409497
Posted Monday, January 21, 2013 5:40 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 9:53 PM
Points: 3,438, Visits: 5,390
tyson.price (1/21/2013)
Any old CICS mainframe programmers here remember calling a deadlock a "deadly embrace"? That wasn't limited to just databases, which were relatively new in my environment (we were still using VSAM), but also the resources that you needed to control.


I remember VSAM. Wasn't the utility to create them called IDCAMS?

Thanks for the trip down memory lane.



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1409510
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse