resourcesratelimits

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

resources-rate-limits

codecov Go Report Card Go Reference license

RPS limiting by used resources (CPU, RAM)

Documentation

Index

Constants

View Source
const (
	DefaultMemoryUsageBarrierPercentage    = 80.0
	DefaultCPUUtilizationBarrierPercentage = 80.0
	FailValue                              = rescommon.FailValue
	DoneValue                              = rescommon.DoneValue
)

Variables

View Source
var (
	SetCPUResourcer = func(res ResourceViewer) Option {
		return func(rlp *resourceLimit) {
			rlp.cpuRes = res
		}
	}
	SetRAMResourcer = func(res ResourceViewer) Option {
		return func(rlp *resourceLimit) {
			rlp.ramRes = res
		}
	}
	SetDebug = func(debug bool) Option {
		return func(rlp *resourceLimit) {
			rescommon.IsDebug = debug
		}
	}
)
View Source
var (
	ErrCPUUtilizationIsZero = errors.New("CPU utilization is zero")
	ErrRAMUtilizationIsZero = errors.New("RAM utilization is zero")

	ErrNoResourcer = errors.New("not any resourcers set")
)

Functions

func Check added in v0.1.3

Types

type Limiter

type Limiter interface {
	// Основной метод
	Limit() *RateReply
	With(ops ...Option) Limiter
}

Limiter интерфейс лимитера.

func MustNew

func MustNew(ops ...Option) Limiter

func New

func New(ops ...Option) (Limiter, error)

type Option

type Option func(*resourceLimit)

type RateReply

type RateReply struct {
	RAMUsed        float64
	CPUUtilization float64
	Time           time.Time
}

type ResourceViewer added in v0.1.3

type ResourceViewer rescommon.ResourceViewer

func AutoCPUSimple added in v0.1.3

func AutoCPUSimple(t rescommon.ResourceType) (ResourceViewer, error)

func AutoLazyCPU added in v0.1.3

func AutoLazyCPU(
	rt rescommon.ResourceConfiger,
	done chan struct{}, dur time.Duration,
) (res ResourceViewer, err error)

func AutoLazyRAM added in v0.1.3

func AutoLazyRAM(
	rt rescommon.ResourceConfiger,
	done chan struct{}, dur time.Duration,
) (res ResourceViewer, err error)

func AutoRAMSimple added in v0.1.3

func AutoRAMSimple(t rescommon.ResourceType) (ResourceViewer, error)

func MustNewLazy added in v0.1.2

func MustNewLazy() (resCPU, resRAM ResourceViewer, done chan struct{})

func MustNewSimple added in v0.1.2

func MustNewSimple() (resCPU, resRAM ResourceViewer)

func NewLazy added in v0.1.2

func NewLazy() (resCPU, resRAM ResourceViewer, done chan struct{}, err error)

func NewSimple added in v0.1.2

func NewSimple() (resCPU, resRAM ResourceViewer, err error)

type Resourcer added in v0.1.3

type Resourcer rescommon.Resourcer

Jump to

Keyboard shortcuts

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