Layered dispatch limiter combining concurrency, throttling, and byte budgets.
Summary
Functions
Returns a specification to start this module under a supervisor.
Set a backoff window (in milliseconds) and mark the dispatch as recently throttled.
Return a snapshot of the dispatch state.
Execute fun while holding the layered dispatch semaphores.
Types
@type option() :: {:name, GenServer.name()} | {:key, term()} | {:registry, Foundation.Semaphore.Counting.registry()} | {:limiter, Foundation.RateLimit.BackoffWindow.limiter()} | {:concurrency, pos_integer()} | {:throttled_concurrency, pos_integer()} | {:byte_budget, pos_integer()} | {:backoff_window_ms, pos_integer()} | {:byte_penalty_multiplier, pos_integer()} | {:acquire_backoff, Foundation.Backoff.Policy.t() | keyword()} | {:sleep_fun, (non_neg_integer() -> any())}
@type snapshot() :: %{ concurrency: %{name: term(), limit: pos_integer()}, throttled: %{name: term(), limit: pos_integer()}, bytes: Foundation.Semaphore.Weighted.t(), backoff_active?: boolean(), acquire_backoff: Foundation.Backoff.Policy.t(), registry: Foundation.Semaphore.Counting.registry(), sleep_fun: (non_neg_integer() -> any()), byte_penalty_multiplier: pos_integer() }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec set_backoff(GenServer.server(), non_neg_integer()) :: :ok
Set a backoff window (in milliseconds) and mark the dispatch as recently throttled.
@spec snapshot(GenServer.server()) :: snapshot()
Return a snapshot of the dispatch state.
@spec start_link([option()]) :: GenServer.on_start()
@spec with_rate_limit(GenServer.server(), non_neg_integer(), (-> result)) :: result when result: any()
Execute fun while holding the layered dispatch semaphores.