limiting

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FlowCounter

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

计数器算法 FlowCounter

func NewFlowCounter

func NewFlowCounter(counterLimit int, window int64) *FlowCounter

NewFlowCounter

func NewFlowCounterByParams

func NewFlowCounterByParams(args ...interface{}) *FlowCounter

NewFlowCounterByParams

func (*FlowCounter) Pass

func (f *FlowCounter) Pass() bool

Pass 是否达到限流 true 达到限流条件 false 还未达到限流

type FlowRollingCounter

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

计数器算法-滑动窗口 FlowRollingCounter

func NewFlowRollingCounter

func NewFlowRollingCounter(counterLimit, subWinNums int, window int64) *FlowRollingCounter

NewFlowCounter counterLimit:总限制数量 subWinNums:子窗口个数 window:窗口大小 这个时间范围内请求个数不得超过counterLimit

func NewFlowRollingCounterByParams

func NewFlowRollingCounterByParams(args ...interface{}) *FlowRollingCounter

NewFlowRollingCounterByParams

func (*FlowRollingCounter) Init

Init

func (*FlowRollingCounter) Pass

func (f *FlowRollingCounter) Pass() bool

Pass 是否达到限流 true 达到限流条件 false 还未达到限流

type Ilimiter

type Ilimiter interface {
	//是否达到限流 true 达到限流条件 false 还未达到限流
	Pass() bool
}

Ilimiter

type LeakyBucket

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

漏桶算法

func NewLeakyBucket

func NewLeakyBucket(counterLimit int, rate float32) *LeakyBucket

NewLeakyBucket

func NewLeakyBucketByParams

func NewLeakyBucketByParams(args ...interface{}) *LeakyBucket

NewLeakyBucketByParams

func (*LeakyBucket) Pass

func (l *LeakyBucket) Pass() bool

Pass 是否达到限流 true 达到限流条件 false 还未达到限流

type LimitFlowType

type LimitFlowType string

LimitFlowType 限流算法

const (
	LIMIT_FLOW_COUNTER         LimitFlowType = "Counter"         //计数器算法-固定窗口
	LIMIT_FLOW_ROLLING_COUNTER LimitFlowType = "Rolling counter" //计数器算法-滑动窗口
	LIMIT_FLOW_LEAKY_BUCKET    LimitFlowType = "Leaky bucket"    //漏桶算法
	LIMIT_FLOW_TOKEN_BUCKET    LimitFlowType = "Token bucket"    //令牌桶
	LIMIT_FLOW_NONE            LimitFlowType = "None"            //不限流
)

type TokenBucket

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

令牌桶算法

func NewTokenBucket

func NewTokenBucket(rate float32) *TokenBucket

NewTokenBucket

func NewTokenBucketByParams

func NewTokenBucketByParams(args ...interface{}) *TokenBucket

NewTokenBucketByParams

func (*TokenBucket) Pass

func (l *TokenBucket) Pass() bool

Pass 是否达到限流 true 达到限流条件 false 还未达到限流

Jump to

Keyboard shortcuts

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