memoryless

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

README

LICENSE: Apache 2.0 AUTHOR: Peter Boothe

Code vendored from https://github.com/m-lab/go/blob/master/memoryless/README.md

Functions which run a given function as a memoryless Poisson process.

This is very useful if your function generates a gauge measurement or it exerts load on the system in some way. By distributing the measurement or load across time, we help ensure that our systems' data is minimally affected.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTimer

func NewTimer(c Config) (*time.Timer, error)

NewTimer constructs a single-shot time.Timer that, if repeatedly used to construct a series of timers, will ensure that the resulting events conform to the memoryless distribution. For more on how this could and should be used, see the comments to Ticker. It is intended to be a drop-in replacement for time.NewTimer.

Types

type Config

type Config struct {
	// Expected records the expected/mean/average amount of time between runs.
	Expected time.Duration
	// Min provides clamping of the randomly produced value. All timers will wait
	// at least Min time.
	Min time.Duration
	// Max provides clamping of the randomly produced value. All timers will take
	// at most Max time.
	Max time.Duration

	// Once is provided as a helper, because frequently for unit testing and
	// integration testing, you only want the "Forever" loop to run once.
	//
	// The zero value of this struct has Once set to false, which means the value
	// only needs to be set explicitly in codepaths where it might be true.
	Once bool
}

func (Config) Check

func (c Config) Check() error

Check whether the config contrains sensible values. It return an error if the config makes no mathematical sense, and nil if everything is okay.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL