TsgcWSRateLimiterProperties › TokenBucket

TokenBucket Property

Token Bucket algorithm configuration: capacity plus refill rate for smooth bursts.

Syntax

property TokenBucket: TsgcRateLimitTokenBucket read FTokenBucket
      write SetTokenBucket;

Default Value

Remarks

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.

Example

// Average 10 req/sec, bursts up to 50
sgcWSRateLimiter1.TokenBucket.Enabled := True;
sgcWSRateLimiter1.TokenBucket.Capacity := 50;
sgcWSRateLimiter1.TokenBucket.RefillRate := 10;
sgcWSRateLimiter1.TokenBucket.RefillIntervalMs := 1000;

Back to Properties