leakybucket

package
v0.0.0-...-ade9fc0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2020 License: MIT Imports: 2 Imported by: 0

README

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Burst  int // Bucket size
	Remain int // Bucket left space
	Rate   int // 1 req/(Rate ms)
	// contains filtered or unexported fields
}

Bucket bucket used to rate limiting

func NewBucket

func NewBucket(burst, rate int) *Bucket

NewBucket create a bucket @param burst[in]: 在同一时间内的最大并发数量 @param rate[in]: 每隔 rate 毫秒,bucket 内的数量减少一个。

func (*Bucket) AddOne

func (b *Bucket) AddOne() bool

AddOne 客户端请求上来的时候,调用这个函数。 如果 bucket 已经满了,则返回 false,表示该客户端请求过于频繁。 如果 bucket 未满,则 bucket 内的数量加一,并返回 true。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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