Skip to content

Maintain ratios of counts as a moving average that can be used as an instantaneous value for a gauge metric. Useful for maintaining error rates, throttle rates and similar ratios for microservices.

License

Notifications You must be signed in to change notification settings

mgrand/moving-weighted-ratio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moving Weighted Ratio

This is a class that can be used to track the ratio of some subset of events to the total number of events. For example, the number of requests that produced an error result to the total number of requests. The ratio is maintained as a weighted moving average. More recent measurements have more weight than older measurements.

The way it works is that there are 15 bit counters provided in groups of two or four. Each can counter in a group can be incremented independently of the others.

The counters are kept as 15 bit quantities. When a counter in a group overflows, all the counters in the group are right-shifted. Right shifting all of the counters in a group handles the overflow while preserving the ratios between them.

These operations are thread-safe and do not block.

About

Maintain ratios of counts as a moving average that can be used as an instantaneous value for a gauge metric. Useful for maintaining error rates, throttle rates and similar ratios for microservices.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages