feat(observability): record event loop stalls in the server trace (#13697)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
ecd3237b18
commit
ee18e56f90
4 files changed
+248
-1
No files matched your search
@@ -87,6 +87,38 @@ Metrics are not written to a local file.
|
||||
|
||||
If OTLP is not configured, metrics still exist in-process, but you will not have a local artifact to inspect.
|
||||
|
||||
### Event Loop Stalls
|
||||
|
||||
`apps/server/src/observability/EventLoopMonitor.ts` samples the server's event loop every 30 s. When
|
||||
the loop stalled for more than 2 s since the previous sample, it records a root
|
||||
`server.eventLoop.stall` span with a warning. The span has trace level `Warn`, so it stays when
|
||||
`T3CODE_TRACE_MIN_LEVEL` is `Warn`. The warning shows in Settings > Diagnostics unless OTLP logs are
|
||||
on. The span time is when the sample ran, not when the stall happened.
|
||||
|
||||
Some delay is not recorded:
|
||||
|
||||
- `delayMaxMs` is the longest stall, and can undercount it by up to 1 s. The 2 s threshold applies to
|
||||
this value, so a stall over 3 s is normally recorded, and a shorter one can be missed. A stall
|
||||
that ends just as a sample runs can be missed too.
|
||||
- Time the computer spends asleep reads as delay on macOS and Windows. So a sample only counts when
|
||||
the loop was busy, not waiting for events, for at least `delayMaxMs`. Busy time covers the whole
|
||||
window, so a short sleep in an otherwise busy window can still record a false stall. The span then
|
||||
shows CPU time far below `delayMaxMs`.
|
||||
- The first sample after launch is skipped. Startup work such as migrations and projection bootstrap
|
||||
can block the loop for seconds on a large database.
|
||||
|
||||
CPU times and page faults cover the whole process over the whole window since the previous sample.
|
||||
The window is nominally 30 s, but a long stall delays the sample and makes the window longer. Other
|
||||
work in the window can hide a wait, so only CPU time far below `delayMaxMs` proves the thread was
|
||||
waiting. Read CPU together with page faults:
|
||||
|
||||
- High `cpuSystemMs` with many page faults means memory pressure. Major faults are reads from disk or swap.
|
||||
On macOS, reads from compressed memory are minor faults plus system CPU.
|
||||
- High `cpuUserMs` with few page faults means JavaScript work or garbage collection.
|
||||
- Low CPU with few major page faults points at synchronous disk I/O, such as SQLite reads or trace
|
||||
file writes.
|
||||
- Many `involuntaryContextSwitches` mean other processes were competing for the CPU.
|
||||
|
||||
### Related Artifacts
|
||||
|
||||
Provider event NDJSON files still exist for provider runtime streams. Those are separate from the main server trace file.
|
||||
@@ -612,6 +644,7 @@ Current high-value span and metric boundaries include:
|
||||
- git command execution and git hook events
|
||||
- terminal session lifecycle
|
||||
- sqlite query execution
|
||||
- event loop stalls (`server.eventLoop.stall`)
|
||||
|
||||
### Current Constraints
|
||||
|
||||
|
||||
Reference in new issue
Block a user