opuntia_srv (opuntia v1.1.2)
View SourceShared shapers.
Summary
Types
This accepts a function that generates the shape, if such shape was too expensive to calculate. Note that for this server, only full buckets and in milliseconds are valid, due to the nature of gen_server call timeouts.
Functions
Shapes the caller from executing the action, asynchronously
Ask server to forget all its shapers
Start-links a shaper server
Shapes the caller from executing the action
Types
-type args() :: #{max_delay => opuntia:delay(), cleanup_interval => seconds(), ttl => seconds()}.
This accepts a function that generates the shape, if such shape was too expensive to calculate. Note that for this server, only full buckets and in milliseconds are valid, due to the nature of gen_server call timeouts.
-type key() :: term().
-type name() :: atom().
-type opuntia_state() :: #opuntia_state{name :: name(), max_delay :: opuntia:delay(), cleanup_ttl :: non_neg_integer(), cleanup_time :: non_neg_integer(), cleanup_ref :: undefined | reference(), shapers :: #{key() := opuntia:shaper()}}.
-type seconds() :: non_neg_integer().
-type shape() :: 0 | #{bucket_size := opuntia:bucket_size(), rate := opuntia:rate(), time_unit := millisecond, start_full := true}.
Functions
-spec request_wait(gen_server:server_ref(), key(), opuntia:tokens(), gen_shape()) -> gen_server:request_id().
Shapes the caller from executing the action, asynchronously
This will do a gen_server:send_request/2
. Usual pattern applies to receive the matching continue.
Ask server to forget all its shapers
Start-links a shaper server
-spec wait(gen_server:server_ref(), key(), opuntia:tokens(), gen_shape()) -> continue | {error, max_delay_reached}.
Shapes the caller from executing the action
This will do an actual blocking gen_server:call/3
.