aimdtokenbucket

package
v0.0.0-...-19f7044 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2016 License: BSD-3-Clause Imports: 2 Imported by: 1

Documentation

Overview

Package aimdtokenbucket implements the additive increase/multiplicative decrease (AIMD) feedback control algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIMDTokenBucket

type AIMDTokenBucket struct {
	// Consume tokens by receiving from the `Bucket` channel.
	Bucket <-chan float64
	// contains filtered or unexported fields
}

func NewAIMDTokenBucket

func NewAIMDTokenBucket(maxFlowPerSecond float64, bucketSize int, recoveryDuration time.Duration) *AIMDTokenBucket

NewAIMDTokenBucket returns a new AIMD token bucket. The bucket will be full initially. You can consume tokens by reading from the Bucket channel. The bucket will refill gradually at a rate that is initially `maxFlowPerSecond` tokens per second and will never exceed that rate. The refill rate will be reduced by up to 50% every time a backoff signal is received. The refill rate will recover gradually and linearly to its initial value over a period of up to `recoveryDuration`.

The value of a token is the rate per second at the time the token was added to the bucket. (The value is useful as a metric, to understand how the system is behaving.)

func (*AIMDTokenBucket) Backoff

func (tb *AIMDTokenBucket) Backoff()

Backoff delivers a backoff signal to an AIMD token bucket. This reduces the rate at which tokens are added to the bucket by a factor of up to two.

func (*AIMDTokenBucket) Stop

func (tb *AIMDTokenBucket) Stop()

Stop turns off an AIMD token bucket. After Stop, no more tokens will be added to the bucket. Stop does not close the bucket channel in order to prevent a read from the channel from succeeding incorrectly.

type Void

type Void struct{}

Jump to

Keyboard shortcuts

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