limit

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Type = "rateLimit"

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	Now() time.Time
	Sleep(time.Duration)
}

Clock is the minimum necessary interface to instantiate a rate limiter with a clock or mock clock, compatible with clocks created using github.com/andres-erbsen/clock.

type Config

type Config struct {
	interceptor.ExtensionConfig `yaml:",inline"`
	Qps                         int `yaml:"qps,omitempty" default:"2048" validate:"gte=0"`
}

type Interceptor

type Interceptor struct {
	// contains filtered or unexported fields
}

func (*Interceptor) BelongTo

func (i *Interceptor) BelongTo() (componentTypes []string)

func (*Interceptor) Category

func (i *Interceptor) Category() api.Category

func (*Interceptor) Config

func (i *Interceptor) Config() interface{}

func (*Interceptor) IgnoreRetry

func (i *Interceptor) IgnoreRetry() bool

func (*Interceptor) Init

func (i *Interceptor) Init(context api.Context) error

func (*Interceptor) Intercept

func (i *Interceptor) Intercept(invoker source.Invoker, invocation source.Invocation) api.Result

func (*Interceptor) Order

func (i *Interceptor) Order() int

func (*Interceptor) Start

func (i *Interceptor) Start() error

func (*Interceptor) Stop

func (i *Interceptor) Stop()

func (*Interceptor) String

func (i *Interceptor) String() string

func (*Interceptor) Type

func (i *Interceptor) Type() api.Type

type Limiter

type Limiter interface {
	// Take should block to make sure that the RPS is met.
	Take() time.Time
}

Limiter is used to rate-limit some process, possibly across goroutines. The process is expected to call Take() before every iteration, which may block to throttle the goroutine.

func NewUnlimited

func NewUnlimited() Limiter

NewUnlimited returns a RateLimiter that is not limited.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures a Limiter.

var WithoutSlack Option = slackOption(0)

WithoutSlack is an Option for ratelimit.New that initializes the limiter without any initial tolerance for bursts of traffic.

func Per

func Per(per time.Duration) Option

Per allows configuring limits for different time windows.

The default window is one second, so New(100) produces a one hundred per second (100 Hz) rate limiter.

New(2, Per(60*time.Second)) creates a 2 per minute rate limiter.

func WithClock

func WithClock(clock Clock) Option

WithClock returns an option for ratelimit.New that provides an alternate Clock implementation, typically a mock Clock for testing.

func WithoutLock

func WithoutLock() Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL