Public: anyone can read this; the crew can change it.
The minute's statement tally takes a caller's stack only on a statement's first and slowest runs: 1 us of overhead a statement, not 12-15 #17668
Merged 12h 5m ago, live in production
kernel/slowsql.ts counts every statement the forge runs, once a minute naming the ten heaviest. It keyed each count by the caller and so built an Error stack on every statement.
-
Reviews
Changes requested — before the latest pushThe idea is right: the stack is taken on a statement's first run and on its slowest-yet runs, so the tally costs about 1 us a statement. Two things need fixing before it lands.
- Memory (fix first). The tally's key moved from the caller, which is a small bounded set, to the full SQL string. Any code that builds SQL with values inlined (IN lists, literals) makes a new key per statement. The map then grows without limit for up to a minute on the serving thread, and each key holds the whole statement text. Key on
sqlHead(sql)or a bounded normalisation, or cap the distinct keys per minute by folding the rest into one overflow row. Note thatsqlHeadon every run costs a regex pass, so measure it against the 1 us claim. - Tests. The change adds two behaviours and the test covers neither. The first is that the stack is not taken on every run. The second is that a slower later run replaces the caller. As written the test passes if
callers(3)is called on every run, which is the old behaviour. Add a test where two calls come from different call sites and the second is slower, so the reported caller is the second. Add one where a faster later run keeps the first caller. The injected clock intimeStatementsmakes both easy.
The tally's log line is also renamed. Check that nothing else (docs, dashboards, log readers) greps for 'statements by caller'.
ApprovedI could not diff against 94833a2f81f2 (the commit is not in the clone), so I read the whole change. No ask is open on it.
The tally is keyed by SQL. A statement takes a stack only on its first run of the minute or when a run is its slowest yet, so the per-statement overhead drops as the title says. The tests cover both parts:
- The caller named is the slowest run's, and a faster later run keeps the first.
- A hundred runs no slower than the first take no stack.
- Ten thousand distinct inlined statements stay bounded, with the rest as one row.
Non-blocking:
MAX_STATEMENTSis a cap. It is justified here because inlined SQL would otherwise grow the map without limit on the serving thread, but keep it as the only bound.Non-blocking: the log message changed from 'statements by caller' to 'statements by SQL'. If any dashboard or script greps for the old text, update it.
Non-blocking: say in the pull that the
(not kept)row exists, so a reader of the log knows what it is. - Memory (fix first). The tally's key moved from the caller, which is a small bounded set, to the full SQL string. Any code that builds SQL with values inlined (IN lists, literals) makes a new key per statement. The map then grows without limit for up to a minute on the serving thread, and each key holds the whole statement text. Key on
-
Checks
shipped production is serving it deploy 5fa2c54
-
History
- The minute's statement tally takes a caller's stack only on a statement's first and slowest runs: 1 us of overhead a statement, not 12-15 cb79d55
- The memory line says what is held: RSS and its anonymous part, and the allocator's churn as a rate, never "committed 126 GiB" (#17667) 59691dc
- Adopting data from before the migration table parses each migration once, not once per earlier one (#17671) 85b9aa9
- Every transaction on a forge's connection takes the write lock first, with the busy retry (#17643) b9554e8
- scripts/boot-profile.ts: boot a copy of a forge's data under the CPU profiler and say what held the thread (#17660) 05bf470
- The newest snapshot is read alone: the backup watch, drill, probe and standby parse one manifest, not fourteen (#17659) c10544f
- Game pages: an operator on a phone finds the five things they came for (#17664) 2d0f5f0
- The cost ledger's chain is walked in a worker: a boot no longer holds the loop 0.5-1 s for it (#17638) 7ce8163
- Merge pull request #17665 from sold/game-restore 07ec5c4
- A snapshot's files are cut off the serving thread: an unchanged hosted forge's stream pass holds the loop 0 ms, not 0.8 s (#17622) 574b021
- Merge main into sold/game-restore dffb002
- A game box's snapshot comes back as a game box, not a forge on its worlds (#17625) 275aa3a
- A machine says what it boots: a forge, a game box or services (#17662) f1cc743
- A search that finds nothing is sent to the crew on Enter (#17648) bd828f9
- A pull that lands while its check runs keeps the check, and a red it ends with is main's, said on the home's first line (#17632) f270a47
- Merge pull request #17649 from sold/game-token 6e291aa
- Games: a player asks the forge in game and is answered from its own data (#17641) 4f237e3
- A machine says what it boots: a forge, a game box or services (#17625) 70e4ecc
- Full suite red: 2 files in check run 01m8w6hr59j962wx5rp8ngjz3e (#17655) 4128d1b
- Keep the last two tokens: a restored forge still answers the box e817733
kernel/slow_sql.ts counts every statement the forge runs, once a minute naming the ten heaviest. It keyed each count by the caller and so built an Error stack on every statement. The boot profile of the stage rig's copy (scripts/boot-profile.ts, #17629) put that stack capture at 2.7 s of 34 s of script on the thread in 150 s, the single largest item after the database-size walk.
Now the tally is by the statement's SQL, and each row names the caller of that statement's slowest run in the minute: the stack is taken on its first run and on a run slower than any before it, which over n runs is about ln(n) times, not n. The line is the same shape (
caller,n,ms,sql), now "statements by SQL, last minute". Two callers of the same SQL share a row; the one named is where it was slowest, which is the one to look at.runner-6, 200,000 indexed reads over 40 statements, two rounds: no tally 7.4-10.5 us a statement a stack per run 18.9-25.7 us first and slowest 9.7-10.8 us
test/loop-stall.test.ts: five inserts are one row of n 5 that names the test as the caller, one line a minute; 10 pass.
Co-Authored-By: Claude Fable 5 <[email protected]>
🤖 Generated with Claude Code