client-gok8s.io/client-go/pkg/util/ratelimit Index | Files

package ratelimit

import "k8s.io/client-go/pkg/util/ratelimit"

Index

Types

type Bucket

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

Bucket models a token bucket

func NewBucketWithRate

func NewBucketWithRate(qps float64, capacity int64) *Bucket

NewBucketWithRate creates a new token bucket, with maximum capacity = initial capacity, and a refill rate of qps We use floats for refill calculations, which introduces the possibility of truncation and rounding errors. For "sensible" qps values though, is is acceptable: jbeda did some tests here https://play.golang.org/p/LSKUOGz2LG

func (*Bucket) Available

func (b *Bucket) Available() int64

Available returns the quantity available in the bucket (which may be negative), but does not take it. This function is for diagnostic / informational purposes only - the returned capacity may immediately be inaccurate if another thread is operating on the bucket concurrently.

func (*Bucket) Capacity

func (b *Bucket) Capacity() int64

Capacity returns the maximum capacity of the bucket

func (*Bucket) Take

func (b *Bucket) Take(n int64) time.Duration

Take takes n units from the bucket, reducing the available quantity even below zero, but then returns the amount of time we should wait

func (*Bucket) TakeAvailable

func (b *Bucket) TakeAvailable(max int64) int64

TakeAvailable immediately takes whatever quantity is available, up to max

func (*Bucket) Wait

func (b *Bucket) Wait(n int64)

Wait combines a call to Take with a sleep call

Source Files

bucket.go

Version
v2.0.0-alpha.1+incompatible
Published
Dec 20, 2016
Platform
js/wasm
Imports
3 packages
Last checked
3 minutes ago

Tools for package owners.