loadshed

package module
v0.0.0-...-9d32939 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

loadshed

We've moved to https://github.com/asecurityteam/loadshed.

This repository is read-only and maintained to support existing users. New development will happen in the new location.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doer

type Doer interface {
	Do(func() error) error
}

Doer is an interface representing load shedding interface with Do method

type Loadshed

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

Loadshed is a struct containing all the aggregators that rejects a percentage of requests based on aggregation of system load data.

func New

func New(options ...Option) *Loadshed

New generators a Loadshed struct that sheds load based on some definition of system load

func (*Loadshed) Do

func (l *Loadshed) Do(runfn func() error) error

Do function inputs a function which returns an error

type Option

type Option func(*Loadshed) *Loadshed

Option is a partial initializer for Loadshed

func Aggregator

func Aggregator(a rolling.Aggregator) Option

Aggregator adds an arbitrary Aggregator to the evaluation for load shedding. The result of the aggregator will be interpreted as a percentage value between 0.0 and 1.0. This value will be used as the percentage of requests to reject.

func AverageLatency

func AverageLatency(lower float64, upper float64, bucketSize time.Duration, buckets int, preallocHint int, requiredPoints int) Option

AverageLatency generates an option that adds average request latency within a rolling time window to the load shedding calculation. If the average value, in seconds, falls between lower and upper then a percentage of new requests will be rejected. The rolling window is configured by defining a bucket size and number of buckets. The preallocHint is an optimisation for keeping the number of alloc calls low. If the hint is zero then a default value is used.

func CPU

func CPU(lower float64, upper float64, pollingInterval time.Duration, windowSize int) Option

CPU generates an option that adds a rolling average of CPU usage to the load shedding calculation. It will configure the Decorator to reject a percentage of traffic once the average CPU usage is between lower and upper.

func Concurrency

func Concurrency(lower int, upper int, wg *WaitGroup) Option

Concurrency generates an option that adds total concurrent requests to the load shedding calculation. Once the requests in flight reaches a value between lower and upper the Decorator will begin rejecting new requests based on the distance between the threshold values.

func ErrorRate

func ErrorRate(lower float64, upper float64, bucketSize time.Duration, buckets int, preallocHint int, requiredPoints int) Option

ErrorRate generates an option that calculates the error rate percentile within a rolling time window to the load shedding calculation. If the error rate value falls between the lower and upper then a percentage of new requests will be rejected. The rolling window is configured by defining a bucket size and number of buckets. The preallocHint is an optimisation for keeping the number of alloc calls low. If the hint is zero then a default value is used.

func PercentileLatency

func PercentileLatency(lower float64, upper float64, bucketSize time.Duration, buckets int, preallocHint int, requiredPoints int, percentile float64) Option

PercentileLatency generates an option much like AverageLatency except the aggregation is computed as a percentile of the data recorded rather than an average. The percentile should be given as N%. For example, 95.0 or 99.0. Fractional percentiles, like 99.9, are also valid.

type Rejected

type Rejected struct {
	Aggregate *rolling.Aggregate
}

Rejected is error returned when a request is rejected because of load shedding

func (Rejected) Error

func (r Rejected) Error() string

type WaitGroup

type WaitGroup struct {
	*sync.WaitGroup
	// contains filtered or unexported fields
}

WaitGroup wraps a sync.WaitGroup to make it usable as a load shedding tool.

func NewWaitGroup

func NewWaitGroup() *WaitGroup

NewWaitGroup generates a specialised WaitGroup that tracks the number of concurrent operations. This implementation also satisfies the Aggregator interface from bitbucket.org/atlassian/rolling so that this can be fed into a calculation of system health.

func (*WaitGroup) Add

func (c *WaitGroup) Add(delta int)

Add some number of concurrent operations.

func (*WaitGroup) Aggregate

func (c *WaitGroup) Aggregate() *rolling.Aggregate

Aggregate returns the current concurrency value

func (*WaitGroup) Done

func (c *WaitGroup) Done()

Done markes an operation as complete and removes the tracking.

func (*WaitGroup) Wait

func (c *WaitGroup) Wait()

Wait for all operations to complete.

Directories

Path Synopsis
wrappers

Jump to

Keyboard shortcuts

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