snippetsqlModerate
How to track blocking that happen for less than a second - SQL Server
Viewed 0 times
trackserversqlthanhappenblockingthatforlesshow
Problem
I am trying to troubleshoot a blocking issue which happens for less than a second.
The OLTP application is very sensitive and has to have an response time of less than 200ms for some transactions as per the agreed SLA.
We had some lock escalation issues with the new code release which we were able to solve with reducing the batch size in the updates.
Even with the small batch size, we suspect that the new sp is blocking the same rows that the OLTP transactions is updating.
I need to find the session that is getting blocked and the resource its waiting on. As per my understanding "blocked process threshold" can set for a minimum of 1 second and so this will not capture the blocking.
I am experimenting with wait_info and wait_completed x events.
Is there any other way we could track this. Thanks
The OLTP application is very sensitive and has to have an response time of less than 200ms for some transactions as per the agreed SLA.
We had some lock escalation issues with the new code release which we were able to solve with reducing the batch size in the updates.
Even with the small batch size, we suspect that the new sp is blocking the same rows that the OLTP transactions is updating.
I need to find the session that is getting blocked and the resource its waiting on. As per my understanding "blocked process threshold" can set for a minimum of 1 second and so this will not capture the blocking.
I am experimenting with wait_info and wait_completed x events.
Is there any other way we could track this. Thanks
Solution
As you are specifically interested in locking rather than general waits the
With a filter on
The above gathers the statements waiting on locks for the threshold amount of time but doesn't give the specific lock resource.
I have never used this event and have no insight into how much overhead this session would cause on your production server.
I found this video on the topic. That does strongly recommend filtering on
It also mentions an old legacy undocumented command
Which (if trace flag 3605 is enabled) dumps out limited information such as the below to the SQL Server error log.
Process 53 waited 6844 ms for S lock on RID: 2:1:120:2 result: OKWAIT
I just mention this in passing as extended events would be clearly preferable anyway as it is documented and much more powerful.
locks_lock_waits extended event sounds more suitable. With a filter on
increment >= 200CREATE EVENT SESSION [locks_lock_waits] ON SERVER
ADD EVENT sqlserver.locks_lock_waits(
ACTION(sqlserver.sql_text)
WHERE ( [sqlserver].[is_system] = 0
AND [increment] >= 200
AND [counter] <= 1000 )
)
ADD TARGET package0.ring_buffer;
GO
ALTER EVENT SESSION [locks_lock_waits]
ON SERVER STATE = start;The above gathers the statements waiting on locks for the threshold amount of time but doesn't give the specific lock resource.
I have never used this event and have no insight into how much overhead this session would cause on your production server.
I found this video on the topic. That does strongly recommend filtering on
counter to reduce the number of events collected and I have done so above.It also mentions an old legacy undocumented command
dbcc lock(StallReportThreshold, 200) -- 200 is threshold in msWhich (if trace flag 3605 is enabled) dumps out limited information such as the below to the SQL Server error log.
Process 53 waited 6844 ms for S lock on RID: 2:1:120:2 result: OKWAIT
I just mention this in passing as extended events would be clearly preferable anyway as it is documented and much more powerful.
Code Snippets
CREATE EVENT SESSION [locks_lock_waits] ON SERVER
ADD EVENT sqlserver.locks_lock_waits(
ACTION(sqlserver.sql_text)
WHERE ( [sqlserver].[is_system] = 0
AND [increment] >= 200
AND [counter] <= 1000 )
)
ADD TARGET package0.ring_buffer;
GO
ALTER EVENT SESSION [locks_lock_waits]
ON SERVER STATE = start;dbcc lock(StallReportThreshold, 200) -- 200 is threshold in msContext
StackExchange Database Administrators Q#144070, answer score: 10
Revisions (0)
No revisions yet.