prioritylimiter

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

Limiter does two things a) limits the number of concurrent requests going upstream b) prioritize the "waiting" requests For prioritization we are using two variables: "priority": that is request complexity, less complexity == more priority "uuid": for requests of equal comlexity, process them ordered by uuid in order do minimize the number of "active" requests

func New

func New(limit int, options ...LimiterOption) *Limiter

New creates a new limiter that allows maximum "limit" requests to "Enter"

func (*Limiter) Active

func (l *Limiter) Active() int

Active returns the number of in progress requests

func (*Limiter) Enter

func (l *Limiter) Enter(ctx context.Context, priority int, uuid string) error

Enter blocks this request until it's turn comes

func (*Limiter) Leave

func (l *Limiter) Leave() error

Leave marks a request as complete

type LimiterOption

type LimiterOption func(*Limiter)

func WithMetrics

func WithMetrics(activeGauge, waitingGauge prometheus.Gauge) LimiterOption

WithMetrics adds prometheus metrics to the Limiter instanace

Jump to

Keyboard shortcuts

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