Module iterator_rate

Passthrough iterators for rate limiting.

Description

Passthrough iterators for rate limiting.

Function Index

leaky_bucket/2Leaky bucket shaper It is almost the same as token_bucket/2, but it doesn't allow bursts so the rate NEVER exceeds leak_rate.
token_bucket/2Token bucket shaper It tries to yield not more than "rate" items from inner iterator per "rate_window_ms" milliseconds window.

Function Details

leaky_bucket/2

leaky_bucket(LeakRate::pos_integer() | float(), InnerI::iterator:iterator(Item)) -> iterator:iterator(Item)

LeakRate: How many items to allow per second; can be a positive float for less than 1

Leaky bucket shaper It is almost the same as token_bucket/2, but it doesn't allow bursts so the rate NEVER exceeds leak_rate.

token_bucket/2

token_bucket(Opts, InnerI::iterator:iterator(Item)) -> iterator:iterator(Item)

Opts: Rate limiter configuration: rate: how many "tokens" to add per time-window (default: 1) window_ms: the size of the time window in milliseconds (default: 1000) capacity: how many tokens can be accumulated for bursts (default: 1)

Token bucket shaper It tries to yield not more than "rate" items from inner iterator per "rate_window_ms" milliseconds window. It uses timer:sleep/1 to slow down if necessary. However it can release bursts of items up to "capacity". This implementation assumes each item of the inner iterator consumes exactly one token.


Generated by EDoc