load

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrServiceOverloaded is returned by Shedder.Allow when the service is overloaded.
	ErrServiceOverloaded = errors.New("service overloaded")
)

Functions

func Disable

func Disable()

Disable lets callers disable load shedding.

func DisableLog

func DisableLog()

DisableLog disables the stat logs for load shedding.

Types

type Promise

type Promise interface {
	// Pass lets the caller tell that the call is successful.
	Pass()
	// Fail lets the caller tell that the call is failed.
	Fail()
}

A Promise interface is returned by Shedder.Allow to let callers tell whether the processing request is successful or not.

type Shedder

type Shedder interface {
	// Allow returns the Promise if allowed, otherwise ErrServiceOverloaded.
	Allow() (Promise, error)
}

Shedder is the interface that wraps the Allow method.

func NewAdaptiveShedder

func NewAdaptiveShedder(opts ...ShedderOption) Shedder

NewAdaptiveShedder returns an adaptive shedder. opts can be used to customize the Shedder.

type ShedderGroup

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

A ShedderGroup is a manager to manage key based shedders.

func NewShedderGroup

func NewShedderGroup(opts ...ShedderOption) *ShedderGroup

NewShedderGroup returns a ShedderGroup.

func (*ShedderGroup) GetShedder

func (g *ShedderGroup) GetShedder(key string) Shedder

GetShedder gets the Shedder for the given key.

type ShedderOption

type ShedderOption func(opts *shedderOptions)

ShedderOption lets caller customize the Shedder.

func WithBuckets

func WithBuckets(buckets int) ShedderOption

WithBuckets customizes the Shedder with given number of buckets.

func WithCpuThreshold

func WithCpuThreshold(threshold int64) ShedderOption

WithCpuThreshold customizes the Shedder with given cpu threshold.

func WithWindow

func WithWindow(window time.Duration) ShedderOption

WithWindow customizes the Shedder with given

type SheddingStat

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

A SheddingStat is used to store the statistics for load shedding.

func NewSheddingStat

func NewSheddingStat(name string) *SheddingStat

NewSheddingStat returns a SheddingStat.

func (*SheddingStat) IncrementDrop

func (s *SheddingStat) IncrementDrop()

IncrementDrop increments the dropped requests.

func (*SheddingStat) IncrementPass

func (s *SheddingStat) IncrementPass()

IncrementPass increments the passed requests.

func (*SheddingStat) IncrementTotal

func (s *SheddingStat) IncrementTotal()

IncrementTotal increments the total requests.

Jump to

Keyboard shortcuts

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