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
- RFC 5766 (relayed traffic accounting)
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
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.
Returns updated state; unchanged when pid is not registered.
Registers pid and returns a fresh atomic counter ref.
The ref is also stored in ETS for cross-process increments.
Removes the byte counter entry for pid.