Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Latest commit

 

History

History
43 lines (28 loc) · 683 Bytes

README.md

File metadata and controls

43 lines (28 loc) · 683 Bytes

wisp-sampling

Utilities for sampling and rate limiting actions.

Usage

A Sampler can be used to test if an action is allowed based on a particular policy.

Rate Limiting

The rate limiting sampler allows a given number of samples per second:

val sampler = Sampler.rateLimiting(1L);

if (sampler.sample()) {
    performAction()
}

Percentage

The percentage sampler allows the given percentage of samples:

val sampler = Sampler.percentage(50);

if (sampler.sample()) {
    performAction()
}

Always

The always sampler allows all samples:

val sampler = Sampler.always();

if (sampler.sample()) {
    performAction()
}