Skip to content

An atomic counter that also tracks and calculates a rate written in Go (Golang).

License

Notifications You must be signed in to change notification settings

enterprizesoftware/rate-counter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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))
}

About

An atomic counter that also tracks and calculates a rate written in Go (Golang).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages