stats

package
v0.0.0-...-177afef Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	Total  int64 // 总调用次数(limiter)
	Failed int64 // 失败次数
	// contains filtered or unexported fields
}

计数器

func NewCounter

func NewCounter() *Counter

func (*Counter) AddRecord

func (c *Counter) AddRecord(idx int64, err error, cost int64)

func (*Counter) Idx

func (c *Counter) Idx() (idx int64)

idx < 0 表示用尽

func (*Counter) Report

func (c *Counter) Report(title string, totalns int64, concurrent int, total int64, echoSize int) error

func (*Counter) Reset

func (c *Counter) Reset(total int64)

type Limiter

type Limiter struct {
	sync.Once
	// contains filtered or unexported fields
}

QPS 限制器

func NewLimiter

func NewLimiter(maxQps int64, window time.Duration) *Limiter

公用全局 Timer reset 减少开销, 但 AddNotify 无法回收, 因此不能频繁创建 Limiter must use *Limiter, 否则配置会被复制导致失效

func (*Limiter) QpsOverrun

func (l *Limiter) QpsOverrun() bool

true 代表 超过上限, maxQps <= 0表示没有上限

func (*Limiter) Reset

func (l *Limiter) Reset(maxQps int64)

has race here but will not appear

type Timer

type Timer struct {
	sync.Once
	// contains filtered or unexported fields
}

全局 Timer, 共享时间周期, 并在到期时执行回调

func NewTimer

func NewTimer(window time.Duration) *Timer

func (*Timer) Now

func (t *Timer) Now() int64

Timer 为共享计时器, 减少系统时间调用

func (*Timer) Window

func (t *Timer) Window() time.Duration

Jump to

Keyboard shortcuts

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