Documentation
¶
Overview ¶
Package rate provides rate limiting functionality at a global, network, and subnet level.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limit ¶
type Limit struct {
// RPS is the rate of requests per second in steady state.
RPS float64
// Burst is the number of requests allowed over the RPS.
Burst int
}
Limit is the configuration for a token bucket rate limiter. The bucket has a capacity of Burst, and is refilled at a rate of RPS tokens per second. Initially, buckets are completley full, i.e. tokens in the bucket is equal to `Burst`. In any given time interval T seconds, maximum events allowed will be `T*RPS + Burst`.
type Limiter ¶
type Limiter struct {
// NetworkPrefixLimits are limits for streams with peer IPs belonging to specific subnets.
// It can be used to increase the limit for trusted networks and decrease the limit for specific networks.
NetworkPrefixLimits []PrefixLimit
// GlobalLimit is the limit for all streams where the peer IP doesn't fall within any
// of the `NetworkPrefixLimits`
GlobalLimit Limit
// SubnetRateLimiter is a rate limiter for subnets.
SubnetRateLimiter SubnetLimiter
// contains filtered or unexported fields
}
Limiter rate limits new streams for a service. It allows setting NetworkPrefix specific, global, and subnet specific limits. Use 0 for no rate limiting. The limiter maintains state that must be periodically cleaned up using Cleanup
type PrefixLimit ¶
PrefixLimit is a rate limit configuration that applies to a specific network prefix.
type SubnetLimit ¶
SubnetLimit is a rate limit configuration that applies to a specific subnet.
type SubnetLimiter ¶
type SubnetLimiter struct {
// IPv4SubnetLimits are the per subnet limits for streams with IPv4 Peers.
IPv4SubnetLimits []SubnetLimit
// IPv6SubnetLimits are the per subnet limits for streams with IPv6 Peers.
IPv6SubnetLimits []SubnetLimit
// GracePeriod is the time to wait to remove a full capacity bucket.
// Keeping a bucket around helps prevent allocations
GracePeriod time.Duration
// contains filtered or unexported fields
}
SubnetLimiter rate limits requests per ip subnet.