Skip to content

Commit

Permalink
Merge #108797
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
craig[bot] and Eric.Yang committed Sep 5, 2023
2 parents 3a12304 + de79e45 commit 407f33e
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 54 deletions.
18 changes: 10 additions & 8 deletions pkg/kv/kvserver/concurrency/lock_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ func (kl *keyLocks) lockHeldDuration(now time.Time) time.Duration {
return now.Sub(minStartTS)
}

// Returns the total amount of time all waiters in the queues of
// Returns the total amount of time all active waiters in the queues of
// readers and locking requests have been waiting on the key referenced in the
// receiver.
//
Expand All @@ -2172,14 +2172,16 @@ func (kl *keyLocks) totalAndMaxWaitDuration(now time.Time) (time.Duration, time.
}
for e := kl.queuedLockingRequests.Front(); e != nil; e = e.Next() {
qg := e.Value
g := qg.guard
g.mu.Lock()
waitDuration := now.Sub(g.mu.curLockWaitStart)
totalWaitDuration += waitDuration
if waitDuration > maxWaitDuration {
maxWaitDuration = waitDuration
if qg.active {
g := qg.guard
g.mu.Lock()
waitDuration := now.Sub(g.mu.curLockWaitStart)
totalWaitDuration += waitDuration
if waitDuration > maxWaitDuration {
maxWaitDuration = waitDuration
}
g.mu.Unlock()
}
g.mu.Unlock()
}
return totalWaitDuration, maxWaitDuration
}
Expand Down
Loading

0 comments on commit 407f33e

Please sign in to comment.