TsgcWSRateLimiter › Properties › TokenBucket
Token Bucket algorithm configuration: capacity plus refill rate for smooth bursts.
property TokenBucket: TsgcRateLimitTokenBucket read FTokenBucket
write SetTokenBucket;
—
Each key owns a bucket of up to Capacity tokens. The bucket refills RefillRate tokens every RefillIntervalMs milliseconds, so the sustained request rate is RefillRate / RefillIntervalMs. Every request consumes one token (or the aCost argument passed to Consume). When the bucket is empty the request is rejected and a RetryAfterSec hint is computed from the refill schedule. Set this as the global default strategy when the API advertises an average rate but you want well-behaved clients to burst up to Capacity back-to-back without being throttled.
// Average 10 req/sec, bursts up to 50
sgcWSRateLimiter1.TokenBucket.Enabled := True;
sgcWSRateLimiter1.TokenBucket.Capacity := 50;
sgcWSRateLimiter1.TokenBucket.RefillRate := 10;
sgcWSRateLimiter1.TokenBucket.RefillIntervalMs := 1000;