lib

package
v0.0.0-...-4d3d43f Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CntModeBefore cntMode = iota + 1 //先记数,再判断是否允许请求,这种可能会导致请求量大的时候,qps较小,导致连续失败
	CntModeAfter                     //判断是否允许请求,之后再记数,这种会友好些,qps较小的时候,一段请求失败之后,下一秒的请求可能会成功
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CounterItem

type CounterItem struct {
	Req uint64
	// contains filtered or unexported fields
}

type SlidingWindow

type SlidingWindow struct {
	Qps     int64              //允许的每秒的最大请求数
	Size    int                //累计多少个滑动时间窗口
	Counter *queue.CircleQueue //计数器

	LastCheckTime time.Time
	// contains filtered or unexported fields
}

SlidingWindow 实现平滑时间窗口的逻辑 每个计数器是以秒为单位的 以循环队列用于存储计时器

func NewSlidingWindow

func NewSlidingWindow(qps int64, size int, cm cntMode) *SlidingWindow

func (*SlidingWindow) AllowRequest

func (sw *SlidingWindow) AllowRequest() bool

func (*SlidingWindow) Debug

func (sw *SlidingWindow) Debug(d bool)

func (*SlidingWindow) String

func (sw *SlidingWindow) String() string

Jump to

Keyboard shortcuts

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