-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collect both DBM active sessions and blocking sessions which are sleeping #14054
Collect both DBM active sessions and blocking sessions which are sleeping #14054
Conversation
Label |
@@ -68,7 +73,8 @@ | |||
INNER JOIN sys.dm_exec_requests req | |||
ON c.connection_id = req.connection_id | |||
CROSS APPLY sys.dm_exec_sql_text(req.sql_handle) qt | |||
WHERE sess.session_id != @@spid AND sess.status != 'sleeping' | |||
WHERE sess.session_id != @@spid | |||
AND (sess.status != 'sleeping' OR sess.session_id IN (SELECT blocking_session_id FROM cteBlocking) OR isnull(req.blocking_session_id, 0) <> 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we looked in the active transactions table this might be a tad bit faster (would be a smaller DMV table)
if a thing is blocking, in a sleeping
state I believe it should always show up there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But would it be possible to have a blocking session not in a transaction? Not sure those would be functionally equivalent.
But I do believe in the idea that we should collect all processes with an active transaction; that seems like a better improvement overall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I do believe in the idea that we should collect all processes with an active transaction; that seems like a better improvement overall.
It would make sense to collect long lasting transactions, especially for inactive sessions - that's usually suspicious, regardless of whether the session is currently blocking anyone. We could implement it as a separate metric.
But would it be possible to have a blocking session not in a transaction?
Yes, in the isolation level where the reader is blocking writers. That's the default setting in on-prem SQL Server.
The new query wit cte looks suspiciously fat, especially if we decide to increase the sampling frequency one day. I addressed the issue of idle blocker for Oracle (https://docs.google.com/document/d/1NjAwb_Mui0FGmyxf5k54AZO-_TVoH6Sm4Vef9SIHvhg/edit?pli=1) and proposed an alternative approach - to extract the information from previous samples, if we captured it once it was active. Haven't checked yet if that's feasible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A subquery to capture idle blockers could slow down the query and might be an impediment for increasing the sampling frequency. If we assume that in most samples we won't find any blockers a better approach could be: while scanning the result set of only active sessions build a set containing blockers spids
. In the end, execute a second query to collect only the most basic information on idle blockers - as they aren't executing anything we could probably omit all the joins. On the downside, this would generate an additional round trip to the database in the case some blockers are found, but I think this is a good trade off, as we're optimizing for the most frequent scenario where there aren't any idle blockers.
23aebdd
to
2c49b63
Compare
Codecov Report
Flags with carried forward coverage won't be shown. Click here to find out more. |
4d25f64
to
ba9a8b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took me some time to review. I think this revised approach presents some maintainability problems I'd prefer to avoid if possible. I suggested an alternative, let me know what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! (I can't approve because I'm the one who originally opened the PR) ✅
Co-authored-by: Justin <[email protected]>
What does this PR do?
This query update handles cases where the root blocker is a sleeping process (and thus is not collected) resulting in missing data from the UI.
Performance of the current query:
Performance of the new query:
TK
Motivation
Additional Notes
Review checklist (to be filled by reviewers)
changelog/
andintegration/
labels attachedqa/skip-qa
label.