ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Server.Admission.Bytes

Description

Brief-wait byte-weighted admission: the Content-Length-weighted instance of Ecluse.Core.Server.Admission.Weighted, capping the aggregate bytes held rather than a count of slots.

The publish path buffers whole request bodies, bounded only per request, so concurrent publishes could otherwise hold many caps' worth of heap at once. The weight is the declared Content-Length, or the per-request cap for a chunked body, and it is reserved before the body is read, so the reservation is always at least the bytes buffered.

Synopsis

Documentation

data ByteAdmission Source #

A process-wide byte-admission handle. The constructor is hidden so only the checked acquire/wait/release operations can mutate it.

newByteAdmission :: Int -> IO ByteAdmission Source #

Allocate a handle over the given byte capacity (clamped to at least one byte), with the shared admissionWaitMicros budget.

withByteAdmission :: MonadUnliftIO m => MetricsPort -> ByteAdmission -> Int -> m a -> m (Maybe a) Source #

Run an action holding the given weight. Nothing is a shed. The weight is clamped to the capacity, because a bound must never deadlock on arithmetic it did not make.

Internals exported for testing

newByteAdmissionTuned :: Int -> Int -> Int -> IO ByteAdmission Source #

Allocate a handle with an explicit waiter-room bound and wait budget (microseconds), so a test exercises the queueing without real-second sleeps.