Documentation
¶
Overview ¶
Package activity provides a decaying activity counter.
A decaying counter is appropriate to estimate the best candidate to evict from, say, a cache, assuming the event stream is some Poisson process.
TODO redo the correction factors.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counter ¶
type Counter struct {
Tau time.Duration // Characteristic (filter decay) time
Value float64 // Decaying value
Timestamp time.Time // Time of last Tick
}
Counter contains a current Value and a Timestamp. To initialize, all you need to provide is Tau, eg
a := Counter{Tau: time.Hour}
Good choices or Tau are larger than the period with which you expect events to happen and small enough that your application adapts to changing circumstances. Eg. if you have an event stream of several events per second, and you have to make decisions about evicting a cache every few minutes, then a tau of a few minutes makes sense.
func Add ¶
Add returns the Activity that would be the result of the two event streams that lead to a and b combined. This is only really meaningful if a.Tau == b.Tau, but we will return an Activity with the min(Tau) of the two and apply a plausible correction factor.
func (Counter) NextExpected ¶
NextExpected returns duration (relative to now) until the next expected event given the state of a, the fact that no new event happened until now, and assuming the event source is a Poisson process with a mean interval time much smaller than our Tau.