rate

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rate

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

func New

func New(windowsSize time.Duration) *Rate

New returns a new rate tracker with a defined window size that must be greater than one millisecond.

func (*Rate) Add

func (r *Rate) Add(count int)

add uses the current time and rounds it down to a window and increments the window's value.

func (*Rate) Rate

func (r *Rate) Rate() float64

rate uses the current window and previous windows' counter to compute a moving-window rate in seconds. the rate is computed by first calculating how far along the current time is in the current window as a ratio between 0 and 1.0. Then, the sum of currentWindowCount + (1 - ratio) * previousWindowCounter is returned as the interpolated counter between the two windows.

Jump to

Keyboard shortcuts

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