limiter

package
v3.1.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Index

Constants

View Source
const (
	HillClimbingLimiter = iota
)

Variables

View Source
var ErrReachLimitation = fmt.Errorf("reach limitation")
View Source
var (
	Verbose = false
)

Functions

func VerboseDebugf

func VerboseDebugf(msg string, args ...interface{})

Types

type HillClimbing

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

HillClimbing is a limiter using HillClimbing algorithm

func (*HillClimbing) Acquire

func (l *HillClimbing) Acquire() (Updater, error)

func (*HillClimbing) Inflight

func (l *HillClimbing) Inflight() uint64

func (*HillClimbing) Remaining

func (l *HillClimbing) Remaining() uint64

type HillClimbingOption

type HillClimbingOption int64
const (
	HillClimbingOptionShrinkPlus HillClimbingOption = -2
	HillClimbingOptionShrink     HillClimbingOption = -1
	HillClimbingOptionDoNothing  HillClimbingOption = 0
	HillClimbingOptionExtend     HillClimbingOption = 1
	HillClimbingOptionExtendPlus HillClimbingOption = 2
)

type HillClimbingUpdater

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

func NewHillClimbingUpdater

func NewHillClimbingUpdater(limiter *HillClimbing) *HillClimbingUpdater

func (*HillClimbingUpdater) DoUpdate

func (u *HillClimbingUpdater) DoUpdate() error

type Limiter

type Limiter interface {
	Inflight() uint64
	Remaining() uint64
	// Acquire inspects the current status of the system:
	// - if reaches the limitation, reject the request immediately.
	// - if not, grant this request and return an Updater defined below.
	Acquire() (Updater, error)
}

func NewHillClimbing

func NewHillClimbing() Limiter

type Updater

type Updater interface {
	// DoUpdate is called once an invocation is finished, it tells Updater that the invocation is finished, and please
	// update the Remaining, Inflight parameters of the Limiter.
	DoUpdate() error
}

Jump to

Keyboard shortcuts

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