limiter

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: Apache-2.0 Imports: 4 Imported by: 9 modules, 8 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLimiterWrapper

func NewLimiterWrapper(conLimit ConcurrencyLimiter, qpsLimit RateLimiter) limit.Updater

NewLimiterWrapper wraps the given ConcurrencyLimiter and RateLimiter into a limit.Updater.

Types

type ConcurrencyLimiter

type ConcurrencyLimiter interface {
	// Acquire reports if next access to the protected resource is allowed.
	Acquire(ctx context.Context) bool

	// Release claims a previous taken access has released the resource.
	Release(ctx context.Context)

	// Status returns the total quota and occupied.
	Status(ctx context.Context) (limit, occupied int)
}

ConcurrencyLimiter limits the number of concurrent access towards the protected resource. The implementation of ConcurrencyLimiter should be concurrent safe.

func NewConcurrencyLimiter deprecated

func NewConcurrencyLimiter(lim int) ConcurrencyLimiter

Deprecated: Use NewConnectionLimiter instead.

func NewConnectionLimiter added in v0.3.3

func NewConnectionLimiter(lim int) ConcurrencyLimiter

NewConnectionLimiter returns a new ConnectionLimiter with the given limit.

type DummyConcurrencyLimiter

type DummyConcurrencyLimiter struct{}

DummyConcurrencyLimiter implements ConcurrencyLimiter but without actual limitation.

func (*DummyConcurrencyLimiter) Acquire

func (dcl *DummyConcurrencyLimiter) Acquire(ctx context.Context) bool

Acquire .

func (*DummyConcurrencyLimiter) Release

func (dcl *DummyConcurrencyLimiter) Release(ctx context.Context)

Release .

func (*DummyConcurrencyLimiter) Status

func (dcl *DummyConcurrencyLimiter) Status(ctx context.Context) (limit, occupied int)

Status .

type DummyRateLimiter

type DummyRateLimiter struct{}

DummyRateLimiter implements RateLimiter but without actual limitation.

func (*DummyRateLimiter) Acquire

func (drl *DummyRateLimiter) Acquire(ctx context.Context) bool

Acquire .

func (*DummyRateLimiter) Status

func (drl *DummyRateLimiter) Status(ctx context.Context) (max, current int, interval time.Duration)

Status .

type LimitReporter

type LimitReporter interface {
	ConnOverloadReport()
	QPSOverloadReport()
}

LimitReporter is the interface define to report(metric or print log) when limit happen

type RateLimiter

type RateLimiter interface {
	// Acquire reports if next access to the protected resource is allowed.
	Acquire(ctx context.Context) bool

	// Status returns the rate limit.
	Status(ctx context.Context) (max, current int, interval time.Duration)
}

RateLimiter limits the access rate towards the protected resource.

func NewQPSLimiter

func NewQPSLimiter(interval time.Duration, limit int) RateLimiter

NewQPSLimiter creates qpsLimiter.

type Updatable

type Updatable interface {
	UpdateLimit(limit int)
}

Updatable is a kind of limiters that support changing the limit dynamically. Note that `UpdateLimit` does not guarantee to be concurrent-safe.

Jump to

Keyboard shortcuts

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