ewlr
Stability: 1 - Experimental
Exponentially Weighted Loss Rate.
Contents
Installation
npm install ewlr
Overview
EWLR is an Exponentially Weighted Loss Rate calculation module to estimate event loss rate.
Usage
To run the below example run:
npm run readme
"use strict"; var EWLR = ; // keep track of last tick and tick intervalvar lastTick = EWLR;var tickInterval = 1000; // 1 second (in milliseconds) var ewlr = ; // update with successewlr; // update with failureewlr; // update with 20% loss rateewlr; // or a less precise 20% loss ratefor var i = 0; i < 1000; i++ ewlr; // tick the required number of times in order to get an accurate loss ratevar shouldTick = EWLR;if shouldTick lastTick = shouldTicknewLastTick; for var i = 0; i < shouldTickrequiredTicks; i++ ewlr; consoledirewlr; // may be 0 if we haven't tick()'ed yet ; // will get 3 ticks if we wait 3 seconds
Tests
npm test
Documentation
EWLR
Public API
- EWLR.getTime()
- EWLR.tickIfNecessary(lastTick, tickInterval)
- new EWLR(config)
- ewlr.rate()
- ewlr.tick()
- ewlr.update([n], [lost])
EWLR.getTime()
- Return: Number Time in milliseconds (for example: 109.372263)
EWLR.tickIfNecessary(lastTick, tickInterval)
lastTick
: Number Time of last tick in milliseconds.tickInterval
: Number Tick interval in milliseconds.- Return: undefined If no tick necessary.
- Return: Object If tick is necessary
lastTick
: Number Time of new last tick to set in millisecondsrequiredTicks
: Number The number of ticks to execute to catch up.
Determines if and how many ticks are necessary.
new EWLR(config)
config
: ObjecttimePeriod
: Number (Default: 1000) Time period in milliseconds.tickInterval
: Number (Default: 1000) Tick inteval in milliseconds.
Creates a new EWLR instance.
ewlr.rate()
- Return: Object
rate
: Number Rate of events. Rate is returned so that it can be determined iflossRate
is meaningful. For example, if rate is 2.504763981949714e-32, the loss rate (even if 20%), may not be meaningful since the tiny rate may mean that no updates have happened for a long time.lossRate
: Number Normalized ([0..1]) loss rate of eventslossRate
: Number Normalized ([0..1]) loss rate of events
Returns the event rate and the normalized loss rate. The rate
is only meant as a liveness/recency measure to see if lossRate
is meaningful.
ewlr.tick()
Update the rate and loss rate estimates in accordance with time period and tick interval.
ewlr.update([n], [lost])
n
: Integer (Default: 1) Number of events to update with.lost
: Integer (Default: 0) Number of lost events to update with (0 < lost <= n)