Tinkex.SamplingDispatch (Tinkex v0.3.4)

View Source

Layered dispatch rate limiting for sampling requests.

Applies:

  1. Global concurrency semaphore (default 400)
  2. Throttled concurrency semaphore when a recent backoff was requested
  3. Byte budget semaphore (5MB baseline, 20× penalty during recent backoff)

Backoff timestamps are tracked with monotonic time to match RateLimiter behavior and keep a brief "recently throttled" window even after the backoff has cleared.

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.

Execute fun while holding layered dispatch semaphores.

Types

snapshot()

@type snapshot() :: %{
  concurrency: %{name: term(), limit: pos_integer()},
  throttled: %{name: term(), limit: pos_integer()},
  bytes: Tinkex.BytesSemaphore.t(),
  backoff_active?: boolean(),
  acquire_backoff: map()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

set_backoff(dispatch, duration_ms)

@spec set_backoff(pid(), non_neg_integer()) :: :ok

Set a backoff window (in milliseconds) and mark the dispatch as recently throttled.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

with_rate_limit(dispatch, estimated_bytes, fun)

@spec with_rate_limit(pid(), non_neg_integer(), (-> result)) :: result
when result: any()

Execute fun while holding layered dispatch semaphores.