globaltokenbucket

package
v2.34.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TakeNFunction is the name of the function used to take N tokens from the bucket.
	TakeNFunction = "TakeN"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GlobalTokenBucket

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

GlobalTokenBucket implements Limiter.

func NewGlobalTokenBucket

func NewGlobalTokenBucket(
	dc *distcache.DistCache,
	name string,
	interval time.Duration,
	maxIdleDuration time.Duration,
	continuousFill bool,
	delayInitialFill bool,
	jobGroup *jobs.JobGroup,
) (*GlobalTokenBucket, error)

NewGlobalTokenBucket creates a new instance of DistCacheRateTracker.

func (*GlobalTokenBucket) Close

func (gtb *GlobalTokenBucket) Close() error

Close cleans up DMap held within the DistCacheRateTracker.

func (*GlobalTokenBucket) GetBucketCapacity

func (gtb *GlobalTokenBucket) GetBucketCapacity() float64

GetBucketCapacity returns the rate limit for the rate limiter.

func (*GlobalTokenBucket) GetPassThrough

func (gtb *GlobalTokenBucket) GetPassThrough() bool

GetPassThrough returns the pass through flag.

func (*GlobalTokenBucket) Name

func (gtb *GlobalTokenBucket) Name() string

Name returns the name of the DistCacheRateTracker.

func (*GlobalTokenBucket) Return

func (gtb *GlobalTokenBucket) Return(ctx context.Context, label string, n float64) (float64, float64)

Return returns n tokens to the bucket.

func (*GlobalTokenBucket) SetBucketCapacity

func (gtb *GlobalTokenBucket) SetBucketCapacity(bucketCapacity float64)

SetBucketCapacity sets the rate limit for the rate limiter.

func (*GlobalTokenBucket) SetFillAmount

func (gtb *GlobalTokenBucket) SetFillAmount(fillAmount float64)

SetFillAmount sets the default fill amount for the rate limiter.

func (*GlobalTokenBucket) SetPassThrough

func (gtb *GlobalTokenBucket) SetPassThrough(passThrough bool)

SetPassThrough sets the pass through flag.

func (*GlobalTokenBucket) Take

Take increments value in label by n and returns whether n events should be allowed along with the remaining value (limit - new n) after increment and the current count for the label. It also returns the wait time at which the tokens will be available.

func (*GlobalTokenBucket) TakeIfAvailable

func (gtb *GlobalTokenBucket) TakeIfAvailable(ctx context.Context, label string, n float64) (bool, time.Duration, float64, float64)

TakeIfAvailable increments value in label by n and returns whether n events should be allowed along with the remaining value (limit - new n) after increment and the current count for the label. If an error occurred it returns true, 0, 0 and 0 (fail open). It also may return the wait time at which the tokens will be available.

Jump to

Keyboard shortcuts

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