distlimiter

package module
v0.0.0-...-3f6edba Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2022 License: MIT Imports: 8 Imported by: 0

README

distlimiter

协调分布式节点可使用的总qps

问题

Q: 某些机器由于redis等remote异常导致报备失败,机器所允许的qps将置0,所有打到这台机器的请求都会失败?

A: 如果distlimiter返回失败,业务侧要负责将请求转发到其他机器

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenUUID

func GenUUID() string

Types

type DistLimiter

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

func NewDistLimiter

func NewDistLimiter(options *Options) *DistLimiter

func (*DistLimiter) Wait

func (dlimiter *DistLimiter) Wait(ctx context.Context, returnIfUnavailable bool) error

type Options

type Options struct {
	Id               string
	TotalQPS         uint32
	HeartbeatSeconds uint32
	Limiter          RateLimiter
	Remote           RemoteStore
	RedisAddr        string
	RedisKey         string
}

type Peer

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

func NewPeer

func NewPeer(totalQPS uint32, remote RemoteStore, options *peerOptions) *Peer

func (*Peer) AdjustQPS

func (peer *Peer) AdjustQPS(peerIDs []string)

func (*Peer) GetId

func (peer *Peer) GetId() string

func (*Peer) GetQPS

func (peer *Peer) GetQPS() uint32

func (*Peer) Pull

func (peer *Peer) Pull()

func (*Peer) Send

func (peer *Peer) Send()

type RateLimiter

type RateLimiter interface {
	Wait(context.Context, bool) error
	SetLimit(uint32)
}

type RemoteStore

type RemoteStore interface {
	Send(now time.Time, entry string) error
	Pull(min time.Time, max time.Time) ([]string, error)
	Clear(util time.Time) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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