Skip to content

Commit

Permalink
concurre:sency: only count active waiter in totalAndMaxWaitDuration m…
Browse files Browse the repository at this point in the history
…etric 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 waiting locking requests' wait time contribution to the total and max waiting duration.

Fixes #108683

Release note: None.
  • Loading branch information
Eric.Yang committed Sep 5, 2023
1 parent 71eaeec commit de79e45
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 de79e45

Please sign in to comment.