limiter

package
v1.5.11 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

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{})

var (

decay = 0.95
// cpu statistics interval (ms)
statInterval time.Duration = 500
cpu *atomic.Uint64

)

func init() {
	cpu = new(atomic.Uint64)
	// get cpu usage statistics regularly
	go cpuStat()
}
func cpuStat() {
	t := time.NewTicker(time.Microsecond * statInterval)

	// prevent cpuStat method from crashing unexpectedly
	defer func() {
		t.Stop()
		if err := recover(); err != nil {
			logger.Warnf("[HillClimbing] cpuStat went down, err: %v, attempting to restart...", err)
			go cpuStat()
		}
	}()

	for range t.C {
		stat :=
	}
}

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() (Updater, error)
}

func NewHillClimbing

func NewHillClimbing() Limiter

type Updater

type Updater interface {
	DoUpdate() error
}

Jump to

Keyboard shortcuts

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