Xirsys.XTurn.Allocate.Bytes (xturn v2.0.0)

Copy Markdown View Source

Lock-free per-allocation relay byte counters.

What problem this solves

The media fast path increments byte counts from many processes without blocking the allocation GenServer. Each allocation registers an :atomics ref in ETS; add_in/2 and add_out/2 update counters on the hot path; merge/2 drains them into %Client.State{} periodically.

Internal note

Billing and quota integrations read merged totals from allocation state.

RFCs

Summary

Functions

Adds nbytes to the inbound relay counter for pid.

Adds nbytes to the outbound relay counter for pid.

Creates the public byte-counter ETS table if it does not exist.

Drains pending atomic counters for pid into state.bytes_in and state.bytes_out.

Registers pid and returns a fresh atomic counter ref.

Removes the byte counter entry for pid.

Functions

add_in(pid, nbytes)

Adds nbytes to the inbound relay counter for pid.

add_out(pid, nbytes)

Adds nbytes to the outbound relay counter for pid.

init()

Creates the public byte-counter ETS table if it does not exist.

merge(state, pid)

Drains pending atomic counters for pid into state.bytes_in and state.bytes_out.

Returns updated state; unchanged when pid is not registered.

register(pid)

Registers pid and returns a fresh atomic counter ref.

The ref is also stored in ETS for cross-process increments.

unregister(pid)

Removes the byte counter entry for pid.