Documentation ¶
Index ¶
- func ThroughputQuantizer(quantum uint32, samplesPerSecond uint64, limits ...int) (increment uint32, refillUnit uint64, scaleUnit uint32)
- type Bucket
- type BucketConfig
- type BucketRefillFunc
- type BucketState
- type ChildBucket
- type Controller
- type ParentBucket
- type ParentRWBucket
- type PeriodManager
- type PeriodRefiller
- type RWBucket
- func (p *RWBucket) CopyRWConfig() (read, write BucketConfig)
- func (p *RWBucket) GetManager() *PeriodManager
- func (p *RWBucket) TakeQuota(max int64) int64
- func (p *RWBucket) TakeQuotaNoWait(max int64) int64
- func (p *RWBucket) TakeReadQuotaNoScale(max uint32) uint32
- func (p *RWBucket) TakeWriteQuota(max int64) int64
- func (p *RWBucket) TakeWriteQuotaNoScale(max uint32) uint32
- func (p *RWBucket) TakeWriteQuotaNoWait(max int64) int64
- func (p *RWBucket) WriteBucket() RateQuota
- type RWChildBucket
- func (p *RWChildBucket) CopyRWConfig() (read, write BucketConfig)
- func (p *RWChildBucket) GetManager() *PeriodManager
- func (p *RWChildBucket) TakeQuota(max int64) int64
- func (p *RWChildBucket) TakeQuotaNoWait(max int64) int64
- func (p *RWChildBucket) TakeReadQuotaNoScale(max uint32) uint32
- func (p *RWChildBucket) TakeWriteQuota(max int64) int64
- func (p *RWChildBucket) TakeWriteQuotaNoScale(max uint32) uint32
- func (p *RWChildBucket) TakeWriteQuotaNoWait(max int64) int64
- func (p *RWChildBucket) WriteBucket() RateQuota
- type RWChildSubBucket
- type RWRateQuota
- type RWSubBucket
- type RateQuota
- type RefillQuota
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) TakeQuotaNoScale ¶
func (*Bucket) TakeQuotaNoWait ¶
type BucketConfig ¶
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 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) TakeQuotaNoWait ¶
func (*RWBucket) TakeReadQuotaNoScale ¶
func (*RWBucket) TakeWriteQuota ¶
func (*RWBucket) TakeWriteQuotaNoScale ¶
func (*RWBucket) TakeWriteQuotaNoWait ¶
func (*RWBucket) WriteBucket ¶
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 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 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
Click to show internal directories.
Click to hide internal directories.