Documentation
¶
Overview ¶
Package rate provides a rate limiter. It implements a classic token bucket algorithm, which can achieve functions such as http api speed limit and network bandwidth speed limit.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limits ¶
type Limits struct {
// contains filtered or unexported fields
}
Limits represents a rate limiter that controls resource allocation over time.
func NewLimits ¶
NewLimits creates a new rate limiter with rate r over period p.
Overflow warning: If the rate r is set to a very large value (e.g., 1G = 1024 * 1024 * 1024) and the period (p) is one second, the internal counters may overflow after approximately 544 years. However, this overflow only occurs if the limiter remains completely idle (i.e., neither peek nor wait is called) for the entire duration. Consider this when designing long-running systems with very high rates.