Vug::RateLimiter
Per-host rate limiter using a sliding window algorithm. Tracks request timestamps per host and enforces a max requests per minute limit. Uses sorted arrays with binary search for O(log n) operations.
Constants
CLEANUP_INTERVAL = 1000
Run cleanup after this many allow? calls to prevent unbounded growth
DEFAULT_MAX_PER_MINUTE = 60
Default max requests per host per minute
WINDOW = 1.minute
Sliding window duration for rate limiting
Constructors
Instance methods
Acquire a rate limit slot for the given host. Returns true if under the limit (slot acquired), false if rate limited. This is a stateful operation — it records the request timestamp.
cleanup
Remove expired entries for hosts that haven't been queried recently. Call periodically (e.g., from a background task) to prevent unbounded growth.
max_per_minute
Source