Repository navigation
feat: sample str0m stats into per-second telemetry deltas (LUM-553) - #18
Merged
Merged
Conversation
Enable str0m statistics (SFU_* sample interval, 1 s by default) and turn its cumulative counters into per-second deltas persisted as TrackSample and PeerSample: bytes, packets, NACK/PLI/FIR, jitter in ms, loss, RTT, transport totals and BWE. ICE state transitions are recorded too. - telemetry::sampler: pure delta arithmetic (no delta on first reading, backwards counters clamp to zero, jitter converted from RTP clock units) - samples are keyed by occupancy and only written for published tracks, so no orphan track_id is ever minted - the codec is recorded on the 1 Hz stats tick, not per packet - end-to-end test: a real ICE/DTLS/SRTP session yields a time series
LUM-553 requires the collection not to degrade what it measures. Ported from the monorepo bench (3e43fae), adapted to the one per-packet lookup left: codecs.entry(mid) in the transport pump. Measured: 20-24 ns per packet, i.e. 2.5-4% of the 580-900 ns fanout, about 0.02% of a core at 50 peers. Sampling costs ~60 ns per track per second, off the hot path.
4 tasks done
FrekiManagarm
force-pushed
the
feat/lum-553-stats-sampling
branch
from
November 3, 2026 23:48
5efce3b to
362ff36
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the SFU-side instrumentation of LUM-553: per participant and per leg, jitter, loss, RTT, NACK/PLI/FIR counters and transport totals now reach
telemetry.track_samples/telemetry.peer_samplesas a per-second time series. This is Task 7 ofdocs/plans/2026-08-30-db-self-hosted-rust.md.PeerConnection::newtakes the sample interval (telemetry.sample_interval, 1 s by default). str0m disables stats by default, which is why jitter/loss/RTT were never measured.telemetry::sampler: pure delta arithmetic. There is no delta on the first reading, a counter going backwards clamps to zero, and jitter is converted from RTP clock units to ms (a zero clock rate givesNone, neverinf).TrackStats,PeerStatsandIceStateevents. Egress stats are ignored on purpose because they would double count.TrackSample,PeerSample,TrackCodecand ICE state/events.Deviations from the plan
Telemetry::published_tracknever mints an id, so no orphantrack_idis produced.HashMap<Mid, _>lookup.to_packetalready does, so no per-packet registry is needed.Failedstate, soIceFailedhas no emitter.Overhead (
cargo bench --bench sampling)The instrumentation costs 20–24 ns per packet, which is 2.5–4 % of the 580–900 ns fanout and about 0.02 % of a core at 50 peers. Sampling itself costs ~60 ns per track per second and runs off the hot path.
Relation to the monorepo branch
origin/feature/lum-553holds the same work done in the former monorepo (apps/sfu, unrelated history). It was never ported to this repo. This PR re-implements it on the current tree and ports its bench. That branch is left untouched.Known gap
A peer switching rooms gets no
TrackPublishedin its new occupancy, so no track samples are written after the switch. This predates this PR and is tracked in LUM-708.Test plan
cargo test: 158 passed, including 8 sampler unit tests, apublished_tracktest, and an end-to-end test intests/room.rswhere a real ICE/DTLS/SRTP session yields ≥ 2 non-zero video deltas with jitter in ms. That test fails when stats are disabled (checked).cargo clippy --all-targets -- -D warningscargo fmt --checkSFU_DATABASE_URL) and check rows intelemetry.track_samples