Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var OpenThrottle = &openThrottle{}
OpenThrottle is a singleton open throttle. An open throttle provides no rate limit.
Functions ¶
func WithBurstLimit ¶
func WithBurstLimit(burstLimit int) func(*throttleOptions)
WithBurstLimit returns an option for ratelimit.New that provides an alternate limit for a burst of requests with an idle throttle.
func WithClock ¶
func WithClock(clock Clock) func(*throttleOptions)
WithClock returns an option for ratelimit.New that provides an alternate Clock implementation, typically a mock Clock for testing.
func WithoutSlack ¶
func WithoutSlack(options *throttleOptions)
WithoutSlack is an option for ratelimit.New that initializes the limiter without any initial tolerance for bursts of traffic.
Types ¶
type Clock ¶
Clock is the minimum necessary interface to instantiate a throttle with a clock or fake clock, compatible with clocks created using github.com/andres-erbsen/clock or go.uber.org/yarpc/internal/clock.
type Option ¶
type Option func(*throttleOptions)
Option is an option for a rate limiter constructor.
type Throttle ¶
type Throttle struct {
// contains filtered or unexported fields
}
Throttle is a rate limiter.
func NewThrottle ¶
NewThrottle returns a Throttle that will limit to the given RPS.
type UnaryInboundMiddleware ¶
type UnaryInboundMiddleware struct {
// contains filtered or unexported fields
}
UnaryInboundMiddleware is a unary inbound middleware that sheds inbound requests above a rate limit, with some slack for bursts.
func NewUnaryInboundMiddleware ¶
func NewUnaryInboundMiddleware(rps int, opts ...Option) (*UnaryInboundMiddleware, error)
NewUnaryInboundMiddleware creates a unary inbound middleware that introduces a throttle, shedding inbound requests if they arrive more often than the configured rate limit.
func (*UnaryInboundMiddleware) Handle ¶
func (m *UnaryInboundMiddleware) Handle(ctx context.Context, req *transport.Request, resw transport.ResponseWriter, next transport.UnaryHandler) error
Handle drops inbound requests with a ResourceExhaustedError if the arrive more frequently than the configured rate limit.
type UnaryInboundMiddlewareConfig ¶
type UnaryInboundMiddlewareConfig struct { // RPS is the maximum requests per second, after which the inbound will // throttle inbound requests with a ResourceExhaustedError of "rate limit // exceeded". RPS int `config:"rps"` // BurstLimit determines how much slack the rate limiter will tolerate for // a burst of requests from an idle state before throttling. // The default is 10. A burstLimit of 0 implies the default. // Use "noSlack" to configure a rate limiter without slack. BurstLimit int `config:"burstLimit"` // NoSlack configures the rate limiter without any slack, even after idling // indefinitely. NoSlack bool `config:"noSlack"` }
UnaryInboundMiddlewareConfig describes how to configure and construct a unary inbound rate limiter.
func (UnaryInboundMiddlewareConfig) Build ¶
func (c UnaryInboundMiddlewareConfig) Build() (*UnaryInboundMiddleware, error)
Build creates a unary inbound rate limit middleware, or returns an error if the configuration is invalid.