Skip to content

Fix throughput chart not updating live (per-snapshot delta, not wall-clock rate)#12

Merged
StrangeNoob merged 1 commit into
mainfrom
throughput-fix
Jun 9, 2026
Merged

Fix throughput chart not updating live (per-snapshot delta, not wall-clock rate)#12
StrangeNoob merged 1 commit into
mainfrom
throughput-fix

Conversation

@StrangeNoob

Copy link
Copy Markdown
Owner

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_total rising 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_total counter is the per-second throughput — with no timing term to destabilize it.

  • web/src/lib/series.ts: replace ratePerSecond (and its Sample arrival-time struct) with processedDelta(prev, cur). A counter reset/flush (cur < prev) yields 0, never negative.
  • web/src/App.tsx: track prevProcessed as a plain number ref; push processedDelta into 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 pass
  • npm run typecheck — clean
  • npm run build — dist rebuilt and committed

…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.
@StrangeNoob

Copy link
Copy Markdown
Owner Author

Code review

No 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 👎.

@StrangeNoob StrangeNoob merged commit c592d7c into main Jun 9, 2026
4 checks passed
@StrangeNoob StrangeNoob deleted the throughput-fix branch June 9, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant