Fix throughput chart not updating live (per-snapshot delta, not wall-clock rate)#12
Merged
Conversation
…k rate The dashboard throughput series divided the processed_total delta by the wall-clock interval between SSE arrivals (Date.now). When snapshots bunch up — a backgrounded tab or a reconnect flushes several within milliseconds — the near-zero denominator produced huge spikes that crushed the auto-scaled sparkline, so the chart only looked right immediately after a reload. The server already pushes one snapshot per ~1s, so the per-snapshot delta of the cumulative processed counter IS the per-second throughput, with no timing term to destabilize it. Replace ratePerSecond (and its Sample arrival-time struct) with processedDelta(prev, cur); App tracks prevProcessed as a plain number ref. A counter reset/flush yields 0, never negative.
Owner
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
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.
Problem
The dashboard's Throughput chart appeared frozen — it only looked correct right after a page reload. Reported as "Throughput is not increasing. I need to refresh the page for this."
Root cause
The client throughput series computed a wall-clock rate:
Δprocessed_total / Δ(Date.now arrival). The server pushes one SSE snapshot per ~1s, but arrivals are not evenly spaced — a backgrounded tab or a reconnect flushes several queued snapshots within milliseconds of each other. Dividing a normal delta by that near-zero interval produced enormous spikes, and because the sparkline auto-scales to its max, one spike crushed every real value to a flat line near the axis. The depth chart was immune because it plots an instantaneous value with no time term.Verified server-side correctness separately (curl + a streaming-fetch probe showed
processed_totalrising at a clean ~1s cadence), so this is purely a client-side derivation bug.Fix
Since the server already emits ~1 snapshot/second, the per-snapshot delta of the cumulative
processed_totalcounter is the per-second throughput — with no timing term to destabilize it.web/src/lib/series.ts: replaceratePerSecond(and itsSamplearrival-time struct) withprocessedDelta(prev, cur). A counter reset/flush (cur < prev) yields0, never negative.web/src/App.tsx: trackprevProcessedas a plainnumberref; pushprocessedDeltainto the throughput window on each snapshot.web/src/lib/series.test.ts: tests for the delta, the idle-tick zero, the reset clamp, and explicitly that bunched arrivals report the true delta (no spike).web/dist: rebuilt embedded bundle.Testing
npm run test— 17/17 passnpm run typecheck— cleannpm run build— dist rebuilt and committed