SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Deadlock


Deadlock

Author
Message
InvisibleCat
InvisibleCat
Old Hand
Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)

Group: General Forum Members
Points: 302 Visits: 606
Hi,

I've been doing some monitoring on one of our SSRS servers and have picked up a dead lock that occurs every morning at 2am, the victim and the deadlocking process are both the system created stored procedure 'dbo.CleanExpiredServerParameters' in the ReportServer database.

I can see that this is removing expired parameters but what I am having trouble determining is what is calling this, we have nothing running at 2am so this must mean that the SSRS instance itself is running this, does anyone know about this procedure? Or how I may be able to resolve the deadlock.

The procedure is running the following code;


CREATE PROCEDURE [dbo].[CleanExpiredServerParameters]
@ParametersCleaned INT OUTPUT
AS
DECLARE @now as DATETIME
SET @now = GETDATE()

DELETE FROM [dbo].[ServerParametersInstance]
WHERE ServerParametersID IN
(SELECT TOP 20 ServerParametersID FROM [dbo].[ServerParametersInstance]
WHERE Expiration < @now
)
SET @ParametersCleaned = @@ROWCOUNT


I've not had much luck in finding anything about it.

Any help you can be would be gratefully appreciated.

Thanks,

Nic
HanShi
HanShi
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8478 Visits: 3718
Run a trace when the deadlock occurs. In the trace you can specify the hostname, loginname, NT domain name, etc. to get more information about the connections involved in the deadlock. Hopefully this will give you more information abouw who/what is execution the statements.

** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
HanShi
HanShi
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8478 Visits: 3718
Could you rewrite the delete statement to:
DELETE TOP (20) FROM [dbo].[ServerParametersInstance] 
WHERE Expiration < @now


This will prevent the query to simultaneously read and delete from the same table.

** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
InvisibleCat
InvisibleCat
Old Hand
Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)

Group: General Forum Members
Points: 302 Visits: 606
HanShi (7/17/2013)
Could you rewrite the delete statement to:
DELETE TOP (20) FROM [dbo].[ServerParametersInstance] 
WHERE Expiration < @now


This will prevent the query to simultaneously read and delete from the same table.


Hi,

Thanks for the reply.

I did think about this, but it's (as far as I can tell) an internal SSRS procedure and I'm a little nervous about messing with it, although if it works, it works I guess.

As for the host, this is coming from the SSRS instance itself.

I'll keep digging for more info but I think I'll try the modified procedure to see if I can lighten the load a little.
ChrisM@Work
ChrisM@Work
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40662 Visits: 20000
HanShi (7/17/2013)
Could you rewrite the delete statement to:
DELETE TOP (20) FROM [dbo].[ServerParametersInstance] 
WHERE Expiration < @now


This will prevent the query to simultaneously read and delete from the same table.


SQL Server already does this for you. Look at the execution plan, specifically the eager spool.

Having said that, this is an odd little stored procedure. In this article, MS says "If you have to use TOP to delete rows in a meaningful chronological order, you must use TOP together with ORDER BY in a subselect statement." I think MS forgot to put the ORDER BY into the subselect - in which case, your version will achieve the same result with only one read instead of two.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
InvisibleCat
InvisibleCat
Old Hand
Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)

Group: General Forum Members
Points: 302 Visits: 606
Thanks for the reply Chris.

I see what you mean, I've modified the query, the execution plans show a marked performance increase which is good.

Guess I'll just see what happens this evening, I just wish I knew what exactly was calling this, I'm guessing it's something internal to SSRS and it's doing routine clean up of expired data, it just seems odd that this occurs every evening at 2am.

Nic
InvisibleCat
InvisibleCat
Old Hand
Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)

Group: General Forum Members
Points: 302 Visits: 606
HanShi (7/17/2013)
Could you rewrite the delete statement to:
DELETE TOP (20) FROM [dbo].[ServerParametersInstance] 
WHERE Expiration < @now


This will prevent the query to simultaneously read and delete from the same table.


Hi,

This has resolved the deadlock, thank you both for your help with this.

Nic
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