rolling

package
v0.0.0-...-12c6a5d Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: MIT Imports: 2 Imported by: 0

README

  1. 参考 Hystrix 实现一个滑动窗口计数器。

答:参考 hystrix-go 中的代码

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Number

type Number struct {
	Buckets map[int64]*numberBucket
	Mutex   *sync.RWMutex
}

Number tracks a numberBucket over a bounded number of time buckets. Currently the buckets are one second long and only the last 10 seconds are kept. 用map来保存最近10秒的数据

func NewNumber

func NewNumber() *Number

NewNumber initializes a RollingNumber struct.

func (*Number) Avg

func (r *Number) Avg(now time.Time) float64

得到平均值

func (*Number) Increment

func (r *Number) Increment(i float64)

Increment increments the number in current timeBucket. 更新数据

func (*Number) Max

func (r *Number) Max(now time.Time) float64

Max returns the maximum value seen in the last 10 seconds. 获取滑动窗口中的最大值

func (*Number) Sum

func (r *Number) Sum(now time.Time) float64

Sum sums the values over the buckets in the last 10 seconds. 计算滑动窗口中所有数据的和

func (*Number) UpdateMax

func (r *Number) UpdateMax(n float64)

UpdateMax updates the maximum value in the current bucket. 更新最大值

Jump to

Keyboard shortcuts

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