leaky_bucket/2 | 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 shaper It tries to yield not more than "rate" items from inner iterator per "rate_window_ms" milliseconds window. |
leaky_bucket(LeakRate::pos_integer() | float(), InnerI::iterator:iterator(Item)) -> iterator:iterator(Item)
Item = any()
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(Opts, InnerI::iterator:iterator(Item)) -> iterator:iterator(Item)
Opts = #{rate => pos_integer(), capacity => pos_integer(), window_ms => pos_integer()}
Item = any()
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