fix(gateway): recover bounded pacing debt
Verify Data Plane / gateway (push) Failing after 3m59s

This commit is contained in:
sechmachine
2026-08-09 20:54:15 +07:00
parent 55afea72a1
commit 122080ab34
8 changed files with 334 additions and 3 deletions
+6
View File
@@ -126,6 +126,7 @@ type fairPacer struct {
type fairPacerFlow struct {
next time.Time
lastSeen time.Time
debt time.Duration
}
const fairPacerMaximumCatchup = 5 * time.Millisecond
@@ -180,9 +181,14 @@ func (p *fairPacer) reserveAt(now time.Time, flow string, bytes int) time.Time {
base = now
} else if lag := now.Sub(base); lag > fairPacerMaximumCatchup {
base = now.Add(-fairPacerMaximumCatchup)
state.debt = min(state.debt+lag-fairPacerMaximumCatchup, nativeApolloVideoQueueLatency-fairPacerMaximumCatchup)
}
numerator := int64(bytes) * int64(len(p.flows)) * int64(time.Second)
delay := time.Duration((numerator + p.bytesPerSecond - 1) / p.bytesPerSecond)
if repayment := min(delay/21, state.debt); repayment > 0 {
delay -= repayment
state.debt -= repayment
}
state.next = base.Add(delay)
p.flows[flow] = state
return state.next