Rate Limiting - jaegertracing/jaeger-lib

Rate limiting is a technique used to control the rate of requests made to a system or service. It helps prevent performance degradation and potential system crashes caused by an overwhelming number of requests. The rate_limiter in the project “jaeger-lib” is implemented in Go and can be found in the file utils/rate_limiter.go.

The rate_limiter uses a token bucket algorithm to manage the rate of requests. This algorithm involves a bucket with a fixed size that can hold a certain number of tokens. Each request made to the system consumes one token from the bucket. The bucket is refilled with tokens at a fixed rate, and if there are not enough tokens in the bucket to handle a request, the request is denied or delayed until enough tokens are available.

Here are some possible options for the rate_limiter and examples for each option:

  1. NewRateLimiter(rate int, burst int) *RateLimiter: This creates a new rate limiter with the specified rate (in requests per second) and burst (maximum number of requests that can be made at once). For example, NewRateLimiter(10, 5) creates a rate limiter that allows up to 10 requests per second with a burst limit of 5.
  2. Allow() bool: This method checks if a request can be made based on the current rate limit. It returns true if the request can be made and false if it cannot. For example, limiter.Allow() checks if a request can be made using the current rate limiter.
  3. Wait(): This method blocks the current goroutine until it is allowed to make a request based on the current rate limit. For example, limiter.Wait() blocks the current goroutine until it is allowed to make a request.

The rate_limiter also includes a test file utils/rate_limiter_test.go with examples of how to use the rate limiter and test its functionality.

Sources: