ratelimiter

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: MIT Imports: 2 Imported by: 0

README

rate-limiter

Golang rate limiter

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiLimiter

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

func NewMultiLimiter

func NewMultiLimiter(calls, burst int, timeFrame time.Duration, tolerance float64) *MultiLimiter

NewMultiLimiter returns the MultiLimiter object similar to RateLimiter object. Calls and Burst control the limiter: calls is the number of calls to limit, and burst is the allowed burst (it fills up over the unused calls). The timeFrame allows to specify over what period the calls are spread and tolerance is a % of extra calls to be tolerated. Eg. tolerance of 5% would allow 105% calls per timeFrame. To use the MultiLimiter, you need to initialize Tenant. The allowed calls are filled up for all tenants peridically, each tenant can have a integer multiple of basic rate. Eg. if you have the basic rate of 100 calls per minute, then you can have tenant with 100, 200, or 300 etc. calls per minute allowed. Each can have a different buffer.

func (*MultiLimiter) AddTenant

func (mrl *MultiLimiter) AddTenant(tenantID string, burst, chunk int)

AddTenant adds a tenant with a config. It also updates a tenant limits with a new config if it exist.

func (*MultiLimiter) HasTenant added in v0.0.2

func (mrl *MultiLimiter) HasTenant(tenantID string) bool

HasTenant checks if such tenant is set up

func (*MultiLimiter) Stop

func (mrl *MultiLimiter) Stop()

func (*MultiLimiter) Wait

func (mrl *MultiLimiter) Wait(tenantID string) bool

Wait is the rate limiting call, use it to 'consume' limit

type RateLimiter

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

func NewRateLimiter

func NewRateLimiter(calls, burst int, timeFrame time.Duration, tolerance float64) *RateLimiter

NewRateLimiter returns the RateLimiter object. Calls and Burst control the limiter: calls is the number of calls to limit, and burst is the allowed burst (it fills up over the unused calls). The timeFrame allows to specify over what period the calls are spread and tolerance is a % of extra calls to be tolerated. Eg. tolerance of 5% would allow 105% calls per timeFrame.

func (*RateLimiter) Stop

func (rl *RateLimiter) Stop()

func (*RateLimiter) Wait

func (rl *RateLimiter) Wait()

Wait is the rate limiting call, use it to 'consume' limit

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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