flowcontrol

package
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

flowcontrol is imported from https://github.com/kubernetes/client-go/tree/master/util/flowcontrol

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	clock.PassiveClock
	Sleep(time.Duration)
}

An injectable, mockable clock interface.

type PassiveRateLimiter

type PassiveRateLimiter interface {
	// TryAccept returns true if a token is taken immediately. Otherwise,
	// it returns false.
	TryAccept() bool
	// Stop stops the rate limiter, subsequent calls to CanAccept will return false
	Stop()
	// QPS returns QPS of this rate limiter
	QPS() float32
}

func NewTokenBucketPassiveRateLimiter

func NewTokenBucketPassiveRateLimiter(qps float32, burst int) PassiveRateLimiter

NewTokenBucketPassiveRateLimiter is similar to NewTokenBucketRateLimiter except that it returns a PassiveRateLimiter which does not have Accept() and Wait() methods.

func NewTokenBucketPassiveRateLimiterWithClock

func NewTokenBucketPassiveRateLimiterWithClock(qps float32, burst int, c clock.PassiveClock) PassiveRateLimiter

NewTokenBucketPassiveRateLimiterWithClock is similar to NewTokenBucketRateLimiterWithClock except that it returns a PassiveRateLimiter which does not have Accept() and Wait() methods and uses a PassiveClock.

type RateLimiter

type RateLimiter interface {
	PassiveRateLimiter
	// Accept returns once a token becomes available.
	Accept()
	// Wait returns nil if a token is taken before the Context is done.
	Wait(ctx context.Context) error
}

func NewFakeAlwaysRateLimiter

func NewFakeAlwaysRateLimiter() RateLimiter

func NewFakeNeverRateLimiter

func NewFakeNeverRateLimiter() RateLimiter

func NewTokenBucketRateLimiter

func NewTokenBucketRateLimiter(qps float32, burst int) RateLimiter

NewTokenBucketRateLimiter creates a rate limiter which implements a token bucket approach. The rate limiter allows bursts of up to 'burst' to exceed the QPS, while still maintaining a smoothed qps rate of 'qps'. The bucket is initially filled with 'burst' tokens, and refills at a rate of 'qps'. The maximum number of tokens in the bucket is capped at 'burst'.

func NewTokenBucketRateLimiterWithClock

func NewTokenBucketRateLimiterWithClock(qps float32, burst int, c Clock) RateLimiter

NewTokenBucketRateLimiterWithClock is identical to NewTokenBucketRateLimiter but allows an injectable clock, for testing.

Jump to

Keyboard shortcuts

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