Tinkex.SamplingDispatch (Tinkex v0.3.4)
View SourceLayered dispatch rate limiting for sampling requests.
Applies:
- Global concurrency semaphore (default 400)
- Throttled concurrency semaphore when a recent backoff was requested
- 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
@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
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec set_backoff(pid(), non_neg_integer()) :: :ok
Set a backoff window (in milliseconds) and mark the dispatch as recently throttled.
@spec start_link(keyword()) :: GenServer.on_start()
@spec with_rate_limit(pid(), non_neg_integer(), (-> result)) :: result when result: any()
Execute fun while holding layered dispatch semaphores.