View Source throttle (util v1.1.5)
Throttle given rate over a number of seconds.
Implementation uses time spacing reservation algorithm where each allocation of samples reserves a fraction of space in the throttling window. The reservation gets freed as the time goes by. No more than the Rate number of samples are allowed to fit in the milliseconds Window.
Link to this section Summary
Functions
Samples to the throttleSamples to the throtlle. Return {FitSamples, State}, where FitSamples are the number of samples that fit in the throttling window. 0 means that the throttler is fully congested, and more time needs to elapse before the throttles gets reset to accept more samples.See also: available/2.
Now current time.Call the lambda F, ensuring that it's not called more frequently than the throttle would allow.
Call M,F,A, ensuring that it's not called more frequently than the throttle would allow.
See also: curr_rps/2.
Rate per second.See also: new/3.
Rate per Window milliseconds. Now is expressesed in microseconds since epoch using now().See also: reset/2.
a_now current time.Link to this section Types
-type throttle() :: #throttle{}.
-type time() :: non_neg_integer().
Link to this section Functions
Samples to the throttle
Samples to the throtlle. Return {FitSamples, State}, where FitSamples are the number of samples that fit in the throttling window. 0 means that the throttler is fully congested, and more time needs to elapse before the throttles gets reset to accept more samples.
See also: available/2.
Now current time.
Call the lambda F, ensuring that it's not called more frequently than the throttle would allow.
Example:1> T = throttle:new(10, 1000). 2> lists:foldl(fun(_,{T1,A}) -> {T2,R} = throttle:call(T1, fun() -> http:get("google.com") end), {T2, [R|A]} end, {T,[]}, lists:seq(1, 100)).
-spec call(#throttle{}, fun(() -> any()), non_neg_integer()) -> {#throttle{}, any()}.
Call M,F,A, ensuring that it's not called more frequently than the throttle would allow.
Example:1> T = throttle:new(10, 1000). 2> lists:foldl(fun(_,{T1,A}) -> {T2,R} = throttle:call(T1, http, get, ["google.com"]), {T2, [R|A]} end, {T,[]}, lists:seq(1, 100)).
-spec call(#throttle{}, atom(), atom(), [any()], non_neg_integer()) -> {#throttle{}, any()}.
See also: curr_rps/2.
-spec new(non_neg_integer()) -> throttle().
Rate per second.
-spec new(non_neg_integer(), non_neg_integer()) -> throttle().
See also: new/3.
Rate per Window milliseconds. Now is expressesed in microseconds since epoch using now().
See also: reset/2.
See also: used/2.
a_now current time.