PhoenixWebTransport.MemoryBudget (phoenix_wtransport v0.1.0)

Copy Markdown View Source

Process-wide cap on outbound parked bytes shared by every WebTransport session.

Per-session caps (max_parked_bytes, default 64 MiB) bound one connection, but nothing stopped N stalled sessions from multiplying that bound by N: 100 wedged sessions could pin 6.4 GB of reference-counted binaries and OOM the node. This budget is the shared ceiling for the whole VM.

Reservations use a single :atomics slot so the per-frame send path stays lock-free (no GenServer round-trip in the hot loop). A reservation is taken when a frame is enqueued and released as its bytes leave the queue, so the counter always reflects live parked bytes.

nil is accepted everywhere as "no shared budget configured", which keeps a standalone listener (tests, one-off scripts) working unchanged.

Summary

Functions

Builds a budget from a configured limit (0 or :infinity disables).

Returns the configured ceiling in bytes, or :infinity.

Creates a budget ceiling in bytes.

Releases bytes previously reserved against budget.

Reserves bytes against budget, returning :ok or :deny.

Returns the reserved bytes, or 0 when no budget is configured.

Types

t()

@type t() :: {reference(), pos_integer()}

Functions

from_limit(max)

@spec from_limit(term()) :: t() | nil

Builds a budget from a configured limit (0 or :infinity disables).

limit(arg1)

@spec limit(t() | nil) :: pos_integer() | :infinity

Returns the configured ceiling in bytes, or :infinity.

new(max)

@spec new(pos_integer()) :: t()

Creates a budget ceiling in bytes.

release(budget, bytes)

@spec release(t() | nil, non_neg_integer()) :: :ok

Releases bytes previously reserved against budget.

reserve(budget, bytes)

@spec reserve(t() | nil, non_neg_integer()) :: :ok | :deny

Reserves bytes against budget, returning :ok or :deny.

used(arg1)

@spec used(t() | nil) :: non_neg_integer()

Returns the reserved bytes, or 0 when no budget is configured.