rate

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Limiter is a simple rate limiter to control how frequently events are allowed to happen.

func NewLimiter

func NewLimiter(l int64, fn clock.NowFn) *Limiter

NewLimiter creates a new rate limiter.

func (*Limiter) IsAllowed

func (l *Limiter) IsAllowed(n int64) bool

IsAllowed returns whether n events may happen now. NB(xichen): If a large request comes in, this could potentially block following requests in the same second from going through. This is a non-issue if the limit is much bigger than the typical batch size, which is indeed the case in the aggregation layer as each batch size is usually fairly small.

func (*Limiter) Limit

func (l *Limiter) Limit() int64

Limit returns the current limit.

func (*Limiter) Reset

func (l *Limiter) Reset(limit int64)

Reset resets the internal state.

Jump to

Keyboard shortcuts

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