perf: burst-friendly MB rate limiter for interactive search

The shared 1 req/sec MB rate limiter was serializing the 3 concurrent
search calls in Phase 1 to ~3s minimum. Interactive search needs short
bursts (3 calls at once) but not sustained throughput.

Split into two MB rate limiters:
- mbSearchLimiter: burst=3, refill=1/sec — allows one search's 3
  concurrent calls to fire immediately, then rate-limits sustained use
- mbBackgroundLimiter: strict 1/sec — gates artist image resolution
  in the indexer to avoid 429s during sustained background work

Added NewRateLimiterBurst(n, b) constructor for configurable burst.

Expected Phase 1 improvement: ~3.5s → ~1s (3 calls fire in parallel
instead of serializing through the limiter).
This commit is contained in:
2026-03-29 21:52:48 -04:00
parent cd0e7cea28
commit fd29a6c99d
2 changed files with 17 additions and 3 deletions
+10
View File
@@ -46,6 +46,16 @@ func NewRateLimiterF(f float64) *RateLimiter {
}
}
// NewRateLimiterBurst returns a rate limiter that allows n requests
// per second with a burst size of b. The burst allows short spikes
// (e.g. 3 concurrent search calls) without queueing, while still
// limiting sustained throughput.
func NewRateLimiterBurst(n, b int) *RateLimiter {
return &RateLimiter{
limiter: rate.NewLimiter(rate.Limit(n), b),
}
}
// Wait blocks until the rate limiter allows the caller to proceed
// or the context is cancelled. Returns ctx.Err() if the context
// expires before a token becomes available.