Documentation
¶
Index ¶
Constants ¶
const ( RateMin = 5.0 // Floor: never go below this RateMax = 500.0 // Ceiling: never exceed this RateBackoffFactor = 0.7 // Reduce to 70% on 429 (like AWS SDK beta) RateRecoveryFactor = 1.1 // +10% on sustained success RateRecoveryAfter = 10 // Successful requests before recovery )
Rate limiting constants. These are exported for testing purposes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdaptiveRateLimiter ¶
type AdaptiveRateLimiter struct {
// contains filtered or unexported fields
}
AdaptiveRateLimiter implements adaptive rate limiting for HTTP requests. It starts disabled (or with an initial rate) and adapts based on throttle responses.
func NewAdaptiveRateLimiter ¶
func NewAdaptiveRateLimiter(initialRate float64, name string) *AdaptiveRateLimiter
NewAdaptiveRateLimiter creates a new adaptive rate limiter. If initialRate is 0, the limiter starts disabled and enables on first throttle. If initialRate > 0, the limiter starts enabled at that rate.
func (*AdaptiveRateLimiter) CurrentRate ¶
func (a *AdaptiveRateLimiter) CurrentRate() float64
CurrentRate returns the current rate limit (requests per second). Returns 0 if disabled.
func (*AdaptiveRateLimiter) IsEnabled ¶
func (a *AdaptiveRateLimiter) IsEnabled() bool
IsEnabled returns whether the rate limiter is currently active.
func (*AdaptiveRateLimiter) RecordSuccess ¶
func (a *AdaptiveRateLimiter) RecordSuccess()
RecordSuccess tracks a successful request. After enough consecutive successes, the rate limit is gradually increased.
func (*AdaptiveRateLimiter) RecordThrottle ¶
func (a *AdaptiveRateLimiter) RecordThrottle()
RecordThrottle enables the limiter (if not already) and reduces the rate. This should be called when a 429 or throttling error is received.