ratelimiter

package
v0.0.0-...-cdc42b6 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ThroughputQuantizer

func ThroughputQuantizer(quantum uint32, samplesPerSecond uint64, limits ...int) (increment uint32, refillUnit uint64, scaleUnit uint32)

Types

type Bucket

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

func NewBucket

func NewBucket(bm *PeriodManager, cfg BucketConfig) *Bucket

func (*Bucket) CopyConfig

func (p *Bucket) CopyConfig() BucketConfig

func (*Bucket) GetManager

func (p *Bucket) GetManager() *PeriodManager

func (*Bucket) TakeQuota

func (p *Bucket) TakeQuota(max int64) int64

func (*Bucket) TakeQuotaNoScale

func (p *Bucket) TakeQuotaNoScale(max uint32) uint32

func (*Bucket) TakeQuotaNoWait

func (p *Bucket) TakeQuotaNoWait(max int64) int64

type BucketConfig

type BucketConfig struct {
	RefillAmount uint32
	Quantum      uint32
	MaxAmount    uint32
}

func BucketConfigByThroughput

func BucketConfigByThroughput(bytePerS int, refillUnit uint64, burst int, quantum uint32) BucketConfig

func (BucketConfig) Check

func (v BucketConfig) Check()

func (BucketConfig) IsZero

func (v BucketConfig) IsZero() bool

func (BucketConfig) Scale

func (v BucketConfig) Scale(refillRatio, maxRatio float32) BucketConfig

type BucketRefillFunc

type BucketRefillFunc func(need uint32) uint32

type BucketState

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

func (*BucketState) ForceRefill

func (p *BucketState) ForceRefill(x uint32)

func (*BucketState) PeriodsToRefill

func (p *BucketState) PeriodsToRefill(periods uint64) uint32

func (*BucketState) TakeQuotaNoScale

func (p *BucketState) TakeQuotaNoScale(max uint32, refillFn BucketRefillFunc) uint32

func (*BucketState) TakeQuotaNoWait

func (p *BucketState) TakeQuotaNoWait(max int64, scale uint32, refillFn BucketRefillFunc) int64

type ChildBucket

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

func NewChildBucket

func NewChildBucket(parent ParentBucket, cfg BucketConfig) *ChildBucket

func NewChildBucketRatio

func NewChildBucketRatio(parent ParentBucket, refillRatio, maxRatio float32) *ChildBucket

func (*ChildBucket) CopyConfig

func (p *ChildBucket) CopyConfig() BucketConfig

func (*ChildBucket) GetManager

func (p *ChildBucket) GetManager() *PeriodManager

func (*ChildBucket) TakeQuota

func (p *ChildBucket) TakeQuota(max int64) int64

func (*ChildBucket) TakeQuotaNoScale

func (p *ChildBucket) TakeQuotaNoScale(max uint32) uint32

func (*ChildBucket) TakeQuotaNoWait

func (p *ChildBucket) TakeQuotaNoWait(max int64) int64

type Controller

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

func NewController

func NewController(trafficUnit uint32, refillPeriod time.Duration) *Controller

func (*Controller) GetIncrement

func (p *Controller) GetIncrement() uint32

func (*Controller) Init

func (p *Controller) Init()

func (*Controller) Root

func (p *Controller) Root() *PeriodManager

func (*Controller) SetIncrement

func (p *Controller) SetIncrement(level uint32)

func (*Controller) Start

func (p *Controller) Start(ctx context.Context)

type ParentBucket

type ParentBucket interface {
	CopyConfig() BucketConfig
	TakeQuotaNoScale(uint32) uint32
}

type ParentRWBucket

type ParentRWBucket interface {
	TakeReadQuotaNoScale(max uint32) uint32
	TakeWriteQuotaNoScale(max uint32) uint32
	CopyRWConfig() (read, write BucketConfig)
}

type PeriodManager

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

func NewPeriodManager

func NewPeriodManager(scale uint32) (*PeriodManager, func(uint))

func (*PeriodManager) NewBucket

func (p *PeriodManager) NewBucket(cfg bucketConfig) *Bucket

func (*PeriodManager) NewRWBucket

func (p *PeriodManager) NewRWBucket(cfgR, cfgW bucketConfig) *RWBucket

type PeriodRefiller

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

func (*PeriodRefiller) GetRefillCount

func (p *PeriodRefiller) GetRefillCount() uint64

func (*PeriodRefiller) TakeQuota

func (p *PeriodRefiller) TakeQuota(max int64, state *BucketState, refillFn BucketRefillFunc) int64

func (*PeriodRefiller) TakeQuotaNoWait

func (p *PeriodRefiller) TakeQuotaNoWait(max int64, state *BucketState, refillFn BucketRefillFunc) int64

type RWBucket

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

func NewRWBucket

func NewRWBucket(bm *PeriodManager, read, write BucketConfig) *RWBucket

func (*RWBucket) CopyRWConfig

func (p *RWBucket) CopyRWConfig() (read, write BucketConfig)

func (*RWBucket) GetManager

func (p *RWBucket) GetManager() *PeriodManager

func (*RWBucket) TakeQuota

func (p *RWBucket) TakeQuota(max int64) int64

func (*RWBucket) TakeQuotaNoWait

func (p *RWBucket) TakeQuotaNoWait(max int64) int64

func (*RWBucket) TakeReadQuotaNoScale

func (p *RWBucket) TakeReadQuotaNoScale(max uint32) uint32

func (*RWBucket) TakeWriteQuota

func (p *RWBucket) TakeWriteQuota(max int64) int64

func (*RWBucket) TakeWriteQuotaNoScale

func (p *RWBucket) TakeWriteQuotaNoScale(max uint32) uint32

func (*RWBucket) TakeWriteQuotaNoWait

func (p *RWBucket) TakeWriteQuotaNoWait(max int64) int64

func (*RWBucket) WriteBucket

func (p *RWBucket) WriteBucket() RateQuota

type RWChildBucket

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

func NewRWChildBucket

func NewRWChildBucket(parent ParentRWBucket, read, write BucketConfig) *RWChildBucket

func NewRWChildBucketRatio

func NewRWChildBucketRatio(parent ParentRWBucket, refillRatio, maxRatio float32) *RWChildBucket

func (*RWChildBucket) CopyRWConfig

func (p *RWChildBucket) CopyRWConfig() (read, write BucketConfig)

func (*RWChildBucket) GetManager

func (p *RWChildBucket) GetManager() *PeriodManager

func (*RWChildBucket) TakeQuota

func (p *RWChildBucket) TakeQuota(max int64) int64

func (*RWChildBucket) TakeQuotaNoWait

func (p *RWChildBucket) TakeQuotaNoWait(max int64) int64

func (*RWChildBucket) TakeReadQuotaNoScale

func (p *RWChildBucket) TakeReadQuotaNoScale(max uint32) uint32

func (*RWChildBucket) TakeWriteQuota

func (p *RWChildBucket) TakeWriteQuota(max int64) int64

func (*RWChildBucket) TakeWriteQuotaNoScale

func (p *RWChildBucket) TakeWriteQuotaNoScale(max uint32) uint32

func (*RWChildBucket) TakeWriteQuotaNoWait

func (p *RWChildBucket) TakeWriteQuotaNoWait(max int64) int64

func (*RWChildBucket) WriteBucket

func (p *RWChildBucket) WriteBucket() RateQuota

type RWChildSubBucket

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

func (*RWChildSubBucket) TakeQuota

func (p *RWChildSubBucket) TakeQuota(max int64) int64

func (*RWChildSubBucket) TakeQuotaNoWait

func (p *RWChildSubBucket) TakeQuotaNoWait(max int64) int64

type RWRateQuota

type RWRateQuota interface {
	RateQuota
	TakeWriteQuota(max int64) int64
	TakeWriteQuotaNoWait(max int64) int64
	WriteBucket() RateQuota
}

type RWSubBucket

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

func (*RWSubBucket) TakeQuota

func (p *RWSubBucket) TakeQuota(max int64) int64

func (*RWSubBucket) TakeQuotaNoWait

func (p *RWSubBucket) TakeQuotaNoWait(max int64) int64

type RateQuota

type RateQuota interface {
	TakeQuota(max int64) int64
	TakeQuotaNoWait(max int64) int64
}

type RefillQuota

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

func (*RefillQuota) Refill

func (p *RefillQuota) Refill(needed uint32, periods uint64, state *BucketState, parentRefillFn func(uint32) uint32) uint32

Jump to

Keyboard shortcuts

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