Repository navigation
sfu: report forwarding latency as p90 instead of the mean - #4920
Conversation
The forwarding-latency metric was the mean transit over all forwarded packets. A mean is dominated by a few slow outliers, so a handful of packets stalled on the forward path (e.g. goroutine scheduling latency) inflated the whole node's reported latency even when nearly every packet was forwarded promptly. Report p90 instead: p90 rising means roughly a tenth of forwarded packets are slow, a broad signal of systemic forwarding load rather than a sparse tail. To read a percentile over the report window, the mergeable per-interval summary now keeps a small power-of-two-bucket histogram of transit instead of running moments (sum, sum-of-squares). Drop the jitter (transit std dev) gauge: nothing consumed it, and any spread is derivable from the forward-latency histogram. The protobuf ForwardJitter field is left in place, now unset, to deprecate separately. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Bucket interpolation assumes a uniform fill, so a single 20ms packet (or uniform traffic) could report a p90 above every observed sample. Clamp the interpolated value to the summary's already-tracked min/max, so a quantile never falls outside the data. Exact for single samples and repeated identical latencies. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Would octave-wide buckets be too coarse near the overload thresholds? The 300us overload threshold falls in [256,512), so a node with its p90 packets clustered around 265us and one with them around 500us could report the same interpolated value (e.g. ~341us in the 850/150-of-1000 case). |
| require.Zero(t, forwardSummary{}.percentile(0.5)) | ||
|
|
||
| // half the samples fast (1us), half a slow tail (100us). The median tracks | ||
| // the fast bulk and ignores the tail -- the reason p50 replaces the mean. |
There was a problem hiding this comment.
nit:leftover - should it be p90?
There was a problem hiding this comment.
yikes, yeah, changed it from median to p90 as I thought p90 is a better metric here. Will fix.
The reported metric is p90; the test comment still said p50 replaced the mean. Reword it to reflect that a percentile, not the mean, is reported. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Will look at this more @milos-lk . Good point. I am thinking of tuning the threshold too. It is 300us currently. But, probably need to change it based on some current data. |
| // forwarding latency and read by the overload controller. p90 tracks a broad | ||
| // slowdown but ignores the sparse tail (a few packets stalled on goroutine | ||
| // scheduling), which shedding cannot fix. | ||
| forwardLatencyPercentile = 0.90 |
There was a problem hiding this comment.
Should this be configurable?
There was a problem hiding this comment.
Thought about making it configurable. Then thought that 10% of packets experiencing some high latency is a good check and can change the other lever, i. e. the threshold. But, making this configurable is still a thread in my head. Will probably make it configurable in a later version.
Octave buckets are too coarse near the overload thresholds: 300us falls in [256,512), so a p90 clustered at ~265us and one at ~500us interpolate to the same value and would trip (or not) identically. Split each octave into four linear sub-buckets so the two land in different buckets, on the correct side of the threshold. Min/max clamping alone does not fix this once a node has a high tail, since its max no longer bounds the interpolation. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Devin Review found 1 new potential issue.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| octave := float64(int64(1) << (i / forwardHistSub)) | ||
| width := octave / forwardHistSub | ||
| lo := octave + float64(i%forwardHistSub)*width | ||
| return lo, lo + width |
There was a problem hiding this comment.
🔴 Sparse tail distorts forwarding latency
With 149 packets at 265µs and one at 500µs in the same octave, percentile reports about 343µs. Their shared bucket interpolates across its full observed range, although the actual p90 is 265µs. The node can falsely cross the 300µs overload threshold.
Learn more
The forwarding summary merges packet counts into octave buckets and uses the resulting p90 as node forwarding latency. The observed minimum and maximum do not describe how samples are distributed inside a bucket. A single packet far from the rest stretches the interpolation range and moves the estimated percentile across a threshold. The same approach can underestimate p90 when one low sample stretches a mostly high-latency bucket.
Example: With 850 packets at 50µs, 149 at 265µs, and one at 500µs, the nearest-rank p90 is 265µs. The last 150 packets share the [256, 512)µs octave, so interpolation gives 265 + (500 - 265) × 50/150 ≈ 343µs.
Recommended fix: Preserve sub-octave counts near decision thresholds, or use a mergeable quantile representation that retains intra-bucket distribution. Add mixed-latency samples sharing an octave to the threshold tests.
Was this helpful? React with 👍 or 👎 to provide feedback.
Replace the quarter-octave split with plain octave buckets that also carry the observed [min, max] of their samples, and interpolate a percentile within that range instead of the bucket's nominal edges. This is exact when a bucket's samples cluster, so a p90 near an overload threshold that falls mid-bucket lands on the correct side of it regardless of bucket width -- no threshold-aware boundaries needed. It subsumes the min/max clamp, since an estimate can no longer leave the observed samples. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Assert milos's full review example exactly: 265us and 500us clusters that octave-nominal interpolation both read as ~341us now read 265us and 500us. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@milos-lk good catch — a plain octave straddling 300µs genuinely can't tell those apart, and I went down a couple of paths (finer sub-octave buckets) before landing on a cleaner one. Each bucket now also keeps the observed Your example now resolves out of the same
|
Still looking at more cases Milos. That is one way to avoid the skew above. But, testing with more splits. |
The summary grew from a small moments struct into a per-bucket histogram (~700 bytes), so the value-receiver addSample copied the whole summary on every drained sample in the flush loop. Mutate in place instead: ~28ns -> ~2ns per sample in the background fold, no behavior change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Split each octave into 8 linear sub-buckets (was plain octaves). With the per-bucket min/max interpolation this reports a tight p90 cluster exactly even when it sits mid-octave: 850x265us + 150x410us now reads 410us (above a 400us threshold) instead of 395.5us, and a lognormal p90 lands within ~0.2us of exact. Per-sample add cost is unchanged (~2ns); cost is ~5KB per summary and a larger but per-report merge. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Bucketing: accuracy vs cost (why eighth-octave)The p90 is estimated from a histogram, so I benchmarked a few bucketings before settling on one. All variants use per-bucket Accuracy — octave vs eighth-octave (p90 in µs, error vs the exact sorted value):
t-digest (benchmarked separately as an exact reference) was within rounding of exact on all of these. Cost:
Takeaway: eighth-octave gets effectively t-digest accuracy — including the mid-bucket case where plain octave under-reports and misses a 400µs threshold — at ~90× cheaper adds and no dependency. The only costs are ~5 KB/summary of memory and a larger (but per-report) merge. Residual error shows only for clusters closer than one sub-bucket (~32µs near 256µs — the 280µs row), which is negligible. The per-packet hot path is untouched throughout; all of this is background-worker cost. |
…7 ➔ v1.13.8) (#2275) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [docker.io/livekit/livekit-server](https://github.com/livekit/livekit) | patch | `v1.13.7` → `v1.13.8` | --- ### Release Notes <details> <summary>livekit/livekit (docker.io/livekit/livekit-server)</summary> ### [`v1.13.8`](https://github.com/livekit/livekit/releases/tag/v1.13.8) [Compare Source](livekit/livekit@v1.13.7...v1.13.8) ##### Added - agent: HTTP endpoints data plane ([#​4779](livekit/livekit#4779)) - use sender report pass through setting to forward abs-capture-time verbatim ([#​4812](livekit/livekit#4812)) - Add sdk lable to session start time and participant join ([#​4885](livekit/livekit#4885)) - Add a local participant method to get recently disconnected ([#​4911](livekit/livekit#4911)) - service: start room composite egress configured in a room preset ([#​4926](livekit/livekit#4926)) ##### Changed - Update github workflows ([#​4446](livekit/livekit#4446)) - Reduce descriptor marshal allocations on Go 1.26.4/linux-amd64 ([#​4681](livekit/livekit#4681)) - config: reject unknown send\_side\_bwe\_pacer, warn on unwired fallback ([#​4804](livekit/livekit#4804)) - Update github.com/livekit/protocol digest to [`a879e94`](livekit/livekit@a879e94) ([#​4864](livekit/livekit#4864)) - Update module github.com/gotesttools/gotestfmt/v2 to v2.5.0 ([#​4865](livekit/livekit#4865)) - Update module github.com/urfave/cli/v3 to v3.11.0 ([#​4867](livekit/livekit#4867)) - Update module golang.org/x/mod to v0.41.0 ([#​4868](livekit/livekit#4868)) - sfu: return VP8 munged header by value to avoid per-packet allocation ([#​4871](livekit/livekit#4871)) - sfu: patch pacer header extensions without per-packet allocation ([#​4872](livekit/livekit#4872)) - Update pion/sdp to get lesser SDP retention ([#​4873](livekit/livekit#4873)) - sfu: skip pacer allocation assertion under the race detector ([#​4874](livekit/livekit#4874)) - sfu: broadcast RTP to down tracks without per-packet allocations ([#​4875](livekit/livekit#4875)) - Track action versions and stop quarantining our own actions ([#​4877](livekit/livekit#4877)) - test: fix two data races in the test suites ([#​4878](livekit/livekit#4878)) - Bump go.opentelemetry.io/otel/sdk ([#​4879](livekit/livekit#4879)) - deps: update psrpc to v0.8.0 ([#​4882](livekit/livekit#4882)) - Update module github.com/moby/moby/client to v0.6.0 ([#​4883](livekit/livekit#4883)) - Update module golang.org/x/sync to v0.23.0 ([#​4884](livekit/livekit#4884)) - Propagate SIP\_TRUNK\_FAILURE ([#​4890](livekit/livekit#4890)) - ccutils: use millisecond resolution for probe interval backoff ([#​4891](livekit/livekit#4891)) - Increase receiver loadbalance threshold when batch io enabled ([#​4899](livekit/livekit#4899)) - rtc: parse each remote offer once per negotiation ([#​4904](livekit/livekit#4904)) - Bump protocol ([#​4909](livekit/livekit#4909)) - rtc: split EndSession out of MoveToRoom ([#​4917](livekit/livekit#4917)) - telemetry: drop the stats worker re-key path ([#​4918](livekit/livekit#4918)) - sfu: report forwarding latency as p90 instead of the mean ([#​4920](livekit/livekit#4920)) - rtc: accept ICE Completed in ICE-restart connect assertions ([#​4921](livekit/livekit#4921)) - rtc: measure data blob keys by their content, not their text form ([#​4923](livekit/livekit#4923)) - Remove deprecatred way of setting prometheus from the config file ([#​4928](livekit/livekit#4928)) - test: give mock participants a connection quality, close test rooms ([#​4933](livekit/livekit#4933)) - update warp dep ([#​4943](livekit/livekit#4943)) ##### Fixed - Do not add down tracks after receiver close ([#​4857](livekit/livekit#4857)) - Do not request media sections for transceivers that cannot send ([#​4892](livekit/livekit#4892)) - Deregister agent job when the server terminates it ([#​4893](livekit/livekit#4893)) - sfu: don't hold bindLock across the blank-frame flush in CloseWithFlush ([#​4895](livekit/livekit#4895)) - dynacast: re-send subscribed qualities after every publisher answer ([#​4907](livekit/livekit#4907)) - agent: release JobTerminate handler when job ends before registration ([#​4908](livekit/livekit#4908)) - Report disconnected for older disconnected participants. ([#​4910](livekit/livekit#4910)) - rtc: record a room's departure when the participant leaves it ([#​4913](livekit/livekit#4913)) - update deps to fix warp issue ([#​4916](livekit/livekit#4916)) - sfu: fix data stats active window bitrate and duration units ([#​4922](livekit/livekit#4922)) - fix: reject instead of drop for no dispatch rule ([#​4927](livekit/livekit#4927)) - fix: skip RTX/FEC when picking a fallback video codec ([#​4930](livekit/livekit#4930)) - fix: do not read invalid delta ([#​4935](livekit/livekit#4935)) - fix: use the fast debounce for the first negotiation ([#​4936](livekit/livekit#4936)) - fix: skip DTLS HelloVerifyRequest ([#​4937](livekit/livekit#4937)) - config: parse generated duration flags as durations ([#​4939](livekit/livekit#4939)) - fix: use the most common recent packet rate in connection quality ([#​4940](livekit/livekit#4940)) - fix: copy RED history packets instead of keeping pointers ([#​4941](livekit/livekit#4941)) - fix: keep one subscription when first subscribes race ([#​4944](livekit/livekit#4944)) - bump protocol to get unlock on no key fix ([#​4945](livekit/livekit#4945)) - fix: count leftover upstream loss after RTX repairs ([#​4946](livekit/livekit#4946)) - fix: switch VP8 temporal layer up only at a layer sync frame ([#​4947](livekit/livekit#4947)) - fix: reconcile everything when the reconcile queue overflows ([#​4948](livekit/livekit#4948)) - fix: enable H.264 publish for desktop Linux Firefox ([#​4949](livekit/livekit#4949)) </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjEzMy4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/2275
…7 → v1.13.9) (#854) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [docker.io/livekit/livekit-server](https://github.com/livekit/livekit) | patch | `v1.13.7` → `v1.13.9` | --- ### Release Notes <details> <summary>livekit/livekit (docker.io/livekit/livekit-server)</summary> ### [`v1.13.9`](https://github.com/livekit/livekit/releases/tag/v1.13.9) [Compare Source](livekit/livekit@v1.13.8...v1.13.9) Please note that release v1.13.8 introduced a behaviour change that caused egress start failures explained in [#​4955](livekit/livekit#4955). This release restores the behaviour to what it was in v1.13.7 and before. ##### Changed - bump protocol and psrpc deps ([#​4958](livekit/livekit#4958)) - sfu/buffer: parse the dependency descriptor without allocating ([#​4953](livekit/livekit#4953)) - sfu/buffer: stop allocating per ingested packet ([#​4951](livekit/livekit#4951)) ##### Fixed - v1 path: check for subscriber_allow_pause presence before using it ([#​4957](livekit/livekit#4957)) - Cap forward-jump loops in SelectorDecisionCache ([#​4952](livekit/livekit#4952)) ### [`v1.13.8`](https://github.com/livekit/livekit/releases/tag/v1.13.8) [Compare Source](livekit/livekit@v1.13.7...v1.13.8) ##### Added - agent: HTTP endpoints data plane ([#​4779](livekit/livekit#4779)) - use sender report pass through setting to forward abs-capture-time verbatim ([#​4812](livekit/livekit#4812)) - Add sdk lable to session start time and participant join ([#​4885](livekit/livekit#4885)) - Add a local participant method to get recently disconnected ([#​4911](livekit/livekit#4911)) - service: start room composite egress configured in a room preset ([#​4926](livekit/livekit#4926)) ##### Changed - Update github workflows ([#​4446](livekit/livekit#4446)) - Reduce descriptor marshal allocations on Go 1.26.4/linux-amd64 ([#​4681](livekit/livekit#4681)) - config: reject unknown send_side_bwe_pacer, warn on unwired fallback ([#​4804](livekit/livekit#4804)) - Update github.com/livekit/protocol digest to [`a879e94`](livekit/livekit@a879e94) ([#​4864](livekit/livekit#4864)) - Update module github.com/gotesttools/gotestfmt/v2 to v2.5.0 ([#​4865](livekit/livekit#4865)) - Update module github.com/urfave/cli/v3 to v3.11.0 ([#​4867](livekit/livekit#4867)) - Update module golang.org/x/mod to v0.41.0 ([#​4868](livekit/livekit#4868)) - sfu: return VP8 munged header by value to avoid per-packet allocation ([#​4871](livekit/livekit#4871)) - sfu: patch pacer header extensions without per-packet allocation ([#​4872](livekit/livekit#4872)) - Update pion/sdp to get lesser SDP retention ([#​4873](livekit/livekit#4873)) - sfu: skip pacer allocation assertion under the race detector ([#​4874](livekit/livekit#4874)) - sfu: broadcast RTP to down tracks without per-packet allocations ([#​4875](livekit/livekit#4875)) - Track action versions and stop quarantining our own actions ([#​4877](livekit/livekit#4877)) - test: fix two data races in the test suites ([#​4878](livekit/livekit#4878)) - Bump go.opentelemetry.io/otel/sdk ([#​4879](livekit/livekit#4879)) - deps: update psrpc to v0.8.0 ([#​4882](livekit/livekit#4882)) - Update module github.com/moby/moby/client to v0.6.0 ([#​4883](livekit/livekit#4883)) - Update module golang.org/x/sync to v0.23.0 ([#​4884](livekit/livekit#4884)) - Propagate SIP_TRUNK_FAILURE ([#​4890](livekit/livekit#4890)) - ccutils: use millisecond resolution for probe interval backoff ([#​4891](livekit/livekit#4891)) - Increase receiver loadbalance threshold when batch io enabled ([#​4899](livekit/livekit#4899)) - rtc: parse each remote offer once per negotiation ([#​4904](livekit/livekit#4904)) - Bump protocol ([#​4909](livekit/livekit#4909)) - rtc: split EndSession out of MoveToRoom ([#​4917](livekit/livekit#4917)) - telemetry: drop the stats worker re-key path ([#​4918](livekit/livekit#4918)) - sfu: report forwarding latency as p90 instead of the mean ([#​4920](livekit/livekit#4920)) - rtc: accept ICE Completed in ICE-restart connect assertions ([#​4921](livekit/livekit#4921)) - rtc: measure data blob keys by their content, not their text form ([#​4923](livekit/livekit#4923)) - Remove deprecatred way of setting prometheus from the config file ([#​4928](livekit/livekit#4928)) - test: give mock participants a connection quality, close test rooms ([#​4933](livekit/livekit#4933)) - update warp dep ([#​4943](livekit/livekit#4943)) ##### Fixed - Do not add down tracks after receiver close ([#​4857](livekit/livekit#4857)) - Do not request media sections for transceivers that cannot send ([#​4892](livekit/livekit#4892)) - Deregister agent job when the server terminates it ([#​4893](livekit/livekit#4893)) - sfu: don't hold bindLock across the blank-frame flush in CloseWithFlush ([#​4895](livekit/livekit#4895)) - dynacast: re-send subscribed qualities after every publisher answer ([#​4907](livekit/livekit#4907)) - agent: release JobTerminate handler when job ends before registration ([#​4908](livekit/livekit#4908)) - Report disconnected for older disconnected participants. ([#​4910](livekit/livekit#4910)) - rtc: record a room's departure when the participant leaves it ([#​4913](livekit/livekit#4913)) - update deps to fix warp issue ([#​4916](livekit/livekit#4916)) - sfu: fix data stats active window bitrate and duration units ([#​4922](livekit/livekit#4922)) - fix: reject instead of drop for no dispatch rule ([#​4927](livekit/livekit#4927)) - fix: skip RTX/FEC when picking a fallback video codec ([#​4930](livekit/livekit#4930)) - fix: do not read invalid delta ([#​4935](livekit/livekit#4935)) - fix: use the fast debounce for the first negotiation ([#​4936](livekit/livekit#4936)) - fix: skip DTLS HelloVerifyRequest ([#​4937](livekit/livekit#4937)) - config: parse generated duration flags as durations ([#​4939](livekit/livekit#4939)) - fix: use the most common recent packet rate in connection quality ([#​4940](livekit/livekit#4940)) - fix: copy RED history packets instead of keeping pointers ([#​4941](livekit/livekit#4941)) - fix: keep one subscription when first subscribes race ([#​4944](livekit/livekit#4944)) - bump protocol to get unlock on no key fix ([#​4945](livekit/livekit#4945)) - fix: count leftover upstream loss after RTX repairs ([#​4946](livekit/livekit#4946)) - fix: switch VP8 temporal layer up only at a layer sync frame ([#​4947](livekit/livekit#4947)) - fix: reconcile everything when the reconcile queue overflows ([#​4948](livekit/livekit#4948)) - fix: enable H.264 publish for desktop Linux Firefox ([#​4949](livekit/livekit#4949)) </details> --- ### Configuration 📅 **Schedule**: (in timezone Europe/London) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNTUuMSIsInVwZGF0ZWRJblZlciI6IjQ0LjE1NS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19--> Reviewed-on: https://git.hayden.moe/hayden/phoebe/pulls/854
What
Report the node's forwarding-latency metric as p90 of packet transit instead of the mean, and remove the unused jitter (std-dev) gauge.
Why
A mean is pulled up by a small number of slow outliers, so a few packets stalled on the forward path (for example goroutine scheduling latency) inflated the whole node's reported latency even when nearly every packet forwarded promptly. p90 rising means roughly 10% of forwarded packets are slow, which is a genuine, broad indication of systemic forwarding load rather than a sparse tail.
How
The mergeable per-interval summary now keeps a small power-of-two-bucket histogram of transit (instead of sum / sum-of-squares), so any percentile can be read over the report window. The per-packet hot path is unchanged.
Jitter is removed: nothing consumed it, and any spread is derivable from the existing
forward_latencyhistogram. The protobufForwardJitterfield is left in place, now unset, to deprecate separately.🤖 Generated with Claude Code