Skip to content

Latest commit

 

History

History
53 lines (36 loc) · 1.34 KB

README.md

File metadata and controls

53 lines (36 loc) · 1.34 KB

rate-counter

About

This library provides you the ability to report the rate of a specific metric (counter). Essentially if functions bout incrementing counters. The library will capture samples over a observance period, and give you the ability query the rate that the counter is incrementing.

Based on your defined interval, rate counter will generate the number of samples necessary to add up to the observance period. Anything out of the observance period is ignored, therefore the reported rate is always accurate.

Performance

This is useful for high-throughput applications, since the rate is regulated by the observance period which should typically be a 1 - 15 second window.

This was designed to perform no memory allocations and run as quickly as possible to refrain from incurring any overhead to the processes it would live in.

There is no background goroutine that does any calculations so this implementation is very efficient.

Install

go get github.com/enterprizesoftware/rate-counter
import "github.com/enterprizesoftware/rate-counter"

Usage

var actions = ratecounter.New(50 * time.Millisecond, 5 * time.Second)

func doTask() {
    actions.Increment()
  
    // do some work
    
}

func printStats() {
    fmt.Println(actions.Total())
    fmt.Println(actions.RatePer(time.Second))
}