ratelimit

package
v0.0.0-...-f3cdb5d Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBackoffMinimum = 10 * time.Second
	DefaultBackoffMaximum = 20 * time.Minute
	DefaultBackoffFactor  = 1.2
	DefaultBackoffJitter  = 0.2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

Limiter is a rate limiter and has an exponential backoff implementation in the event of too many errors which further reduces the rate of operations.

In the context of taskscaler, it's used when scaling up instances, and caps how many instances can be requested per second. It has the ability to burst, so for example, if you allow 100 requests per second, but have not requested anything for 1 second, you'll immediately be able to request 100.

If taskscaler tells the limiter that too many errors have occurred, no scaling can happen until after an exponential backoff delay.

func New

func New(limit, burst int) *Limiter

New returns a new rate limiter.

func (*Limiter) Delay

func (l *Limiter) Delay() (time.Duration, bool)

Delay returns the current delay and whether the delay has been adjusted since the last call.

func (*Limiter) Failure

func (l *Limiter) Failure()

Failure registers a failure. Each failure exponentially increases the delay before N returns >0.

func (*Limiter) LimitBurst

func (l *Limiter) LimitBurst() (int, int)

LimitBurst returns the limit and burst settings.

func (*Limiter) N

func (l *Limiter) N(n int) int

N returns rate limited n, this can be 0 if there's no bucket capacity or if we're delayed due to exponential backoff.

func (*Limiter) SetBackoff

func (l *Limiter) SetBackoff(minimum, maximum time.Duration, factor, jitter float64)

SetBackoff sets a custom backoff, factor and jitter.

func (*Limiter) Success

func (l *Limiter) Success()

Success registers a success. This only resets the failure count if the failure delay has been exceeded.

Jump to

Keyboard shortcuts

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