Skip to content

Commit 407f33e

Browse files
craig[bot]Eric.Yang
craig[bot]
and
Eric.Yang
committed
Merge #108797
108797: concurrency: only count active waiter in totalAndMaxWaitDuration metric calculation r=arulajmani a=lyang24 concurrency: only count active waiter in totalAndMaxWaitDuration metric calculation. The lock wait duration should only apply for the waiters that are actively waiting. This change has no effect on wating readers since all waiting readers are active. We are excluding all inactive locking requests' wait time contribution to the total and max waiting duration. Fixes: #108683 Release note: None. Co-authored-by: Eric.Yang <[email protected]>
2 parents 3a12304 + de79e45 commit 407f33e

File tree

2 files changed

+176
-54
lines changed

2 files changed

+176
-54
lines changed

pkg/kv/kvserver/concurrency/lock_table.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,7 @@ func (kl *keyLocks) lockHeldDuration(now time.Time) time.Duration {
21522152
return now.Sub(minStartTS)
21532153
}
21542154

2155-
// Returns the total amount of time all waiters in the queues of
2155+
// Returns the total amount of time all active waiters in the queues of
21562156
// readers and locking requests have been waiting on the key referenced in the
21572157
// receiver.
21582158
//
@@ -2172,14 +2172,16 @@ func (kl *keyLocks) totalAndMaxWaitDuration(now time.Time) (time.Duration, time.
21722172
}
21732173
for e := kl.queuedLockingRequests.Front(); e != nil; e = e.Next() {
21742174
qg := e.Value
2175-
g := qg.guard
2176-
g.mu.Lock()
2177-
waitDuration := now.Sub(g.mu.curLockWaitStart)
2178-
totalWaitDuration += waitDuration
2179-
if waitDuration > maxWaitDuration {
2180-
maxWaitDuration = waitDuration
2175+
if qg.active {
2176+
g := qg.guard
2177+
g.mu.Lock()
2178+
waitDuration := now.Sub(g.mu.curLockWaitStart)
2179+
totalWaitDuration += waitDuration
2180+
if waitDuration > maxWaitDuration {
2181+
maxWaitDuration = waitDuration
2182+
}
2183+
g.mu.Unlock()
21812184
}
2182-
g.mu.Unlock()
21832185
}
21842186
return totalWaitDuration, maxWaitDuration
21852187
}

0 commit comments

Comments
 (0)