throttler

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Setup

func Setup(conf *config.RedisConf, logger *logrus.Logger) error

Setup creates a new throttler

Types

type Limiter

type Limiter struct {
	Read     int64 `json:"read"`
	Write    int64 `json:"write"`
	Interval int64 `json:"interval"`
}

Limiter is the detail limit of the token

type Throttler

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

Throttler is the QPS throttler for publish/consume

func GetThrottler

func GetThrottler() *Throttler

GetThrottler returns the global throttler

func (*Throttler) Add

func (t *Throttler) Add(pool, namespace, token string, limiter *Limiter) error

Add adds the token into the throttler, returns error if the token has already existed

func (*Throttler) Delete

func (t *Throttler) Delete(pool, namespace, token string) error

Delete the token from the throttler

func (*Throttler) Get

func (t *Throttler) Get(pool, namespace, token string) *Limiter

Get the token's limiter if exists

func (*Throttler) GetAll

func (t *Throttler) GetAll(forceUpdate bool) []TokenLimiter

GetAll returns all limiters

func (*Throttler) IsReachRateLimit

func (t *Throttler) IsReachRateLimit(pool, namespace, token string, isRead bool) (bool, error)

IsReachRateLimit checks whether the read or write op reached limit

func (*Throttler) RemedyLimiter

func (t *Throttler) RemedyLimiter(pool, namespace, token string, isRead bool) error

RemedyLimiter would remedy the limiter when consume/produce go wrong

func (*Throttler) Set

func (t *Throttler) Set(pool, namespace, token string, limiter *Limiter) error

Set the token into the throttler

func (*Throttler) Shutdown added in v1.0.4

func (t *Throttler) Shutdown()

Shutdown stops the throttler async update goroutine

type TokenLimiter

type TokenLimiter struct {
	Namespace string  `json:"namespace"`
	Token     string  `json:"token"`
	Limiter   Limiter `json:"limiter"`
}

TokenLimiter is limit of the token

Jump to

Keyboard shortcuts

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