View Source opuntia_srv (opuntia v1.1.0)

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

-type args() :: #{max_delay => opuntia:delay(), cleanup_interval => seconds(), ttl => seconds()}.
-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.
-type key() :: term().
-type name() :: atom().
-type opuntia_state() :: #opuntia_state{}.
-type seconds() :: non_neg_integer().
-type shape() ::
    0 |
    #{bucket_size := opuntia:bucket_size(),
      rate := opuntia:rate(),
      time_unit := millisecond,
      start_full := true}.

Functions

Link to this function

request_wait(Shaper, Key, Tokens, Config)

View Source

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
-spec start_link(name(), args()) -> ignore | {error, _} | {ok, pid()}.
Start-links a shaper server
Link to this function

wait(Shaper, Key, Tokens, Config)

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