ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Server.Admission.Weighted

Description

The weighted door/wait/shed admission core behind serve admission (Ecluse.Core.Server.Admission) and byte-weighted publish admission (Ecluse.Core.Server.Admission.Bytes).

A handle caps the aggregate weight held at once and keeps a bounded room of waiters. Capacity is taken directly only when the room is empty, so a newcomer never jumps a non-empty room, though wake order within the room is not FIFO. The wait budget equals the shed path's Retry-After: 1 hint, so nothing is refused faster than the client was told to wait.

Synopsis

Documentation

data WeightedAdmission Source #

The bounded handle's mutable state and its tuning. The constructor stays hidden so only the checked acquire, wait, and release operations can mutate it.

newWeightedAdmission :: Int -> Int -> Int -> IO WeightedAdmission Source #

Allocate a handle over a capacity, a waiter-room bound, and a wait budget (microseconds). The capacity is verbatim, the wrapper owning that policy, and the other two floor at zero.

withWeightedAdmission :: MonadUnliftIO m => AdmissionObservers -> WeightedAdmission -> Int -> m a -> m (Maybe a) Source #

Run an action holding the given weight. Nothing is a shed, at a full room or an expired wait. The weight is used as given, and released on every exit path, cancellation included.

data AdmissionObservers Source #

The metric hooks the door/wait/release bracket calls. The shared machine owns no telemetry vocabulary, so each instance records under its own signals.

Constructors

AdmissionObservers 

Fields

  • onQueued :: IO ()

    A request that had to wait cleared the wait and is now admitted. Serve admission records its queued metric here. Byte admission does nothing.

  • onShed :: IO ()

    The request was shed: refused at a full door, or its wait outlived the budget. Byte admission records its shed metric here. Serve admission is silent.

  • onInFlightDelta :: Int -> IO ()

    Move the in-flight gauge by the signed weight. Both calls run under the acquire mask, so the gauge is paired on every path.

admissionWaitMicros :: Int Source #

The wait budget (microseconds) before a busy acquisition is shed, deliberately equal to the shed path's Retry-After: 1 hint, so nothing is refused faster than the client was told.