opuntia_srv (opuntia v1.1.2)

View Source

Shared 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

args/0

-type args() :: #{max_delay => opuntia:delay(), cleanup_interval => seconds(), ttl => seconds()}.

gen_shape/0

-type gen_shape() :: fun(() -> shape()) | shape().

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.

key/0

-type key() :: term().

name/0

-type name() :: atom().

opuntia_state/0

-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()}}.

seconds/0

-type seconds() :: non_neg_integer().

shape/0

-type shape() ::
          0 |
          #{bucket_size := opuntia:bucket_size(),
            rate := opuntia:rate(),
            time_unit := millisecond,
            start_full := true}.

Functions

request_wait(Shaper, Key, Tokens, Config)

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.

reset_shapers(ProcName)

Ask server to forget all its shapers

start_link(Name, Args)

-spec start_link(name(), args()) -> ignore | {error, _} | {ok, pid()}.

Start-links a shaper server

wait(Shaper, Key, Tokens, Config)

-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.