feat(router): share the token-size estimate through Redis

With redis.sharedState on, each observed sample also adds to day counters of prompt bytes, prompt tokens and sample count per model. The router-learning loop reads the counters of the routers' target models and keeps one fleet ratio per model. The estimate prefers that ratio once the fleet has the same minimum sample count as the local calibrator. Dropped counter writes only blur the estimate. With the switch off, the calibrator runs its local code only and makes no store call.
This commit is contained in:
2026-11-26 03:32:03 +00:00
parent fe5e9afdc9
commit e70eb32336
4 changed files with 236 additions and 3 deletions
+5
View File
@@ -24,6 +24,11 @@ func (g *Gateway) wireSharedState(cfg *Config) {
brk.failureThreshold, brk.openBase, brk.openMax, 2*brk.openMax))
}
g.shareDecisionBreakers(ids)
if g.tokenCalib != nil && g.limiter != nil {
g.tokenCalib.share(
func(entries []counterIncr) { g.limiter.countAsync(entries) },
func() time.Time { return g.limiter.now() })
}
}
// maxProviderTimeout is the longest request timeout any provider can run, which bounds how long an in-flight count stays live.