rate

package
v2.8.4-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: BSD-3-Clause Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rate is a thread-safe rate tracker with per second resolution. Under the hood, it sums counts over a sliding window split into buckets. A count stays in the rate for at least one window and at most one window (rounded up to whole buckets) plus one bucket, so the rate reaches zero no earlier than one window after the last Add.

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(windowSize 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 increments the bucket for the current time by count. Counts that are not positive are ignored.

func (*Rate) Rate

func (r *Rate) Rate() float64

Rate returns the per second rate over the most recent window.

Jump to

Keyboard shortcuts

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