perf: notify only the next WAL admission waiter

This commit is contained in:
pingqiu committed 2026-12-02 05:46:31 -08:00
1 parent 7bd43c8604
commit c652a6a2f7
2 files changed
+10 -6

No files matched your search

@@ -41,7 +41,6 @@ type walAdmission struct {
active *walAdmissionTicket // an admitted append cannot be preempted
nextOrder uint64
headVersion uint64
changed chan struct{}
sem chan struct{} // counting semaphore for concurrent appenders
walUsed func() float64
notifyFn func() // wakes flusher
@@ -9,6 +9,7 @@ import (
// capacity decision. Granting the next ticket earlier permits it to consume
// the oldest writer's capacity even if semaphore grants were in FIFO order.
type walAdmissionTicket struct {
ready chan struct{}
prev, next *walAdmissionTicket
arrival time.Time
order uint64
@@ -26,7 +27,7 @@ func (a *walAdmission) newCommandOrder() uint64 {
func (a *walAdmission) enqueueTicket(arrival *walWriteArrival) *walAdmissionTicket {
a.queueMu.Lock()
defer a.queueMu.Unlock()
t := &walAdmissionTicket{arrival: time.Now()}
t := &walAdmissionTicket{arrival: time.Now(), ready: make(chan struct{}, 1)}
if arrival != nil {
t.arrival, t.order = arrival.arrival, arrival.order
} else {
@@ -59,16 +60,20 @@ func (a *walAdmission) enqueueTicket(arrival *walWriteArrival) *walAdmissionTick
func (a *walAdmission) notifyHeadLocked() {
a.headVersion++
if a.changed != nil {
close(a.changed)
if a.first != nil {
// Only the new head needs to wake. A buffered notification also covers
// a previously displaced head without waking every queued command.
select {
case a.first.ready <- struct{}{}:
default:
}
}
a.changed = make(chan struct{})
}
func (a *walAdmission) headState(t *walAdmissionTicket) (bool, <-chan struct{}, uint64) {
a.queueMu.Lock()
defer a.queueMu.Unlock()
return a.first == t, a.changed, a.headVersion
return a.first == t, t.ready, a.headVersion
}
func (a *walAdmission) tryGrantTicket(t *walAdmissionTicket, version uint64) bool {