Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lthibault/jitterbug
Tickers with random jitter
https://github.com/lthibault/jitterbug
gonum jitter random stochastic ticker time
Last synced: 1 day ago
JSON representation
Tickers with random jitter
- Host: GitHub
- URL: https://github.com/lthibault/jitterbug
- Owner: lthibault
- License: mit
- Created: 2018-08-02T13:50:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-12T02:00:18.000Z (almost 3 years ago)
- Last Synced: 2024-11-07T17:02:56.840Z (9 days ago)
- Topics: gonum, jitter, random, stochastic, ticker, time
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 89
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jitterbug
Tickers with random jitter
[![Godoc Reference](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/lthibault/jitterbug/v2)
[![Go Report Card](https://goreportcard.com/badge/github.com/SentimensRG/ctx?style=flat-square)](https://goreportcard.com/report/github.com/lthibault/jitterbug)Jitterbug provides functionality similar to `time.Ticker`, but with a configurable random jitter.
Jitterbug has no external dependencies, has a stable API, and is production-ready.
## Installation
```bash
go get -u github.com/lthibault/jitterbug/v2
```## Usage
Jitterbug is used by instantiating a `jitterbug.Ticker` with an interval and a
`jitterbug.Jitter`. The former specifies a baseline interval for the ticker,
to which a jitter is added by the latter.```go
package mainimport (
"log""github.com/lthibault/jitterbug"
)func main() {
t := jitterbug.New(
time.Millisecond * 300,
&jitterbug.Norm{ Stdev: time.Millisecond * 100 },
)// jitterbug.Ticker behaves like time.Ticker
for tick := range t.C {
log.Println(tick)
}
}```
Jitterbug is compatible with the univariate distributions from [GoNum](https://godoc.org/gonum.org/v1/gonum/stat/distuv). For example:
```go
t := jitterbug.New(
time.Millisecond * 300,
&jitterbug.Univariate{
Sampler: &distruv.Gamma{
// Tip: cast time.Duration as float64 when using gonum's distruv
Alpha: float64(time.Millisecond * 100),
Beta: float64(time.Millisecond * 200),
}
},
)
```## Compatible libraries
- [GoNum](https://github.com/gonum/gonum), specifically the [univariate distributions](https://godoc.org/gonum.org/v1/gonum/stat/distuv).
- [Suture](https://github.com/thejerf/suture) can use jitterbug for it's backoff [durations](https://pkg.go.dev/github.com/thejerf/suture/v4#Jitter).