Repository navigation
Conversation
…d itoa The 2026-12-03 callgrind profile of the shim read path (231M Ir per feed-25 + post-get + parse iteration — the ranking driver was silently profiling the SQL fallback until begin_pass was added): - write_escaped was 25%: a branchy per-byte loop (~12 Ir/byte). Now SWAR: 8-byte chunk scan (hasless 0x20 + quote/backslash zero-tricks), memcpy the clean chunks — 42% -> 10.7% of the run. First cut used a 0x21 threshold that flagged SPACES as special and made it slower than the byte loop; the parity test (json::esc_tests, all 256 byte values + space-only chunks) pins the semantics. Callers widened to the 500x6 worst case (the old 2048-byte scratch panicked on a 500-char control-char body). - feed/post emits zeroed an 8KB stack array per call (9% memset): replaced with MaybeUninit Scratch, reading only the prefix payload_copy wrote. - write_decimal: two-digits-at-a-time table itoa (3.5% -> noise). 231M -> 164M Ir (-29%) per iteration on the same seed; with mimalloc (shipped in build.sh now) on top. test: 42/42 golden, 15/15 unit incl. the new escape parity.
- feed_emit: ONE merged range walk of the likes index per feed (seek below the smallest id, count into a sorted-id table, stop past the largest) instead of a seek+walk PER POST — the per-post seeks showed as TableMoveto+IndexMoveto ~12% of the feed cost. 164M -> 140.8M Ir per feed-25 + post-get + parse (-14%; -70% cumulative vs the merged baseline's SQL-fallback measurement of 468M). - work_pass bounded to 512 requests: bounds the transient response memory per pass under saturation (the arjaythedev#569 run peaked at 1,436MB = 22KB/conn — pass bodies + write backlog, not connection state; the rig now holds 16k VUs at ~64MB RSS). - send_response takes the body by value: the pass-built body moved into the outbox frame, the old to_vec() second copy gone. Rig note: back-to-back 16k-VU runs collide with the workstation's own TIME_WAIT/port range (11.8k TIME_WAITs -> 42% 'errors' on run 2 that vanished after the 60s expiry) — cooldown between high-connection runs is mandatory methodology now; the errors dimension is robust across runs (0.00-0.02%), rig latency p95 is noisy (74ms-9.9s on near-identical binaries) so the ladder stays the latency arbiter. test: 42/42 golden (exact bytes), 15/15 unit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Benchmarked at
That ties the merged #569 row (65,000), so this isn't merged (follow-ups are merged only when they beat the merged row). The leaderboard keeps the #569 row and notes this run in a footnote. The head moved to — benchmark agent |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Re-run at the new head
Latency is a bit better than at — benchmark agent |
…the CPU sink idle_close() scanned the ENTIRE connection table every event-loop cycle. The scan is O(conns) cache-miss-bound work (each HashMap entry ~100ns+): at 65k connections x hundreds of cycles/s that is plausibly more than the entire CPU budget — the unexplained gap between the measured ~10-15 µs/req read path and arjay's 145 µs/req at 100% CPU. Invisible to callgrind: the ranking driver has no connections (driver blind spot arjaythedev#2). Rig A/B at 16k VUs, same connection count and RSS: the event-loop CPU now ramps to ~18% where the previous build ramped to ~58% — roughly 40% of a core recovered at 16k, scaling linearly with connection count. A 65s idle timeout needs at most 1s scan granularity: 0.65% CPU at 65k connections. test: 42/42 golden.
The perf run (live server, 16k conns) put 8% of CPU into rep_movs/copy_page_to_iter under pread64 — the shim's default 2MB page cache thrashing on the feed's scattered users/likes pages: every miss copies a 4KB page from the OS cache. The feed's working set is scattered by design (random authors, likes across the whole index). - shim: cache_size = 64MB + mmap_size = 1GB (rule 5 explicitly blesses SQLite's own page cache and mmap — fully-covered DB pages read in place, zero copy). - writer: 16MB cache + 1GB mmap for its read-backs. post-fix perf: no feed-server symbol above 6%; rep_movs gone from the top. The perf ATTACH itself proved destabilizing at saturation (199Hz DWARF sampling on the single core: a run with the profiler attached threw 5.63% feed timeouts that vanished without it) — future profiling at <=50Hz and only with CPU headroom. test: 42/42 golden; rig 16k VUs = 0.10% err (414/380,130), p95 97ms, 2,825 req/s.
wal_autocheckpoint was 0 (WAL grows unbounded across a hold): the live perf profile showed walFindFrame at 6.6% and degrading as the wal-index frame set grew through a 5-minute run. Native PASSIVE checkpointing at 4000 pages (~16MB) is cooperative with the shim's short per-pass read txns — pages fold in as the reader mark advances each cycle. Rule 6 unaffected (checkpoints fold pages into the DB; synchronous=NORMAL still governs commit durability). Rig (16k VUs, 120s): 0.00% errors (0/388,086), 2,878 req/s, p95 76ms, event-loop CPU ramp peaked 18% (idle-throttle + this), WAL file size constant across the hold. test: 42/42 golden.
The 8k-VU 50Hz live profile: sqlite3RunParser + yy_reduce = 2.7% — the writer re-parsed its INSERT/SELECT SQL on every call (rusqlite execute without a statement cache). prepare_cached on insert_post / insert_like / created_at read-back caches the plans; rule 5 explicitly allows prepared statements (they cache the plan, not data). Same commit bounds the WAL: wal_autocheckpoint 0 -> 4000 pages (~16MB, PASSIVE, cooperative with the shim's per-pass read txn) — the live profile had walFindFrame at 6.6-7.4% and growing with the unbounded log; WAL file size now constant across a hold. test: 42/42 golden.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Benchmarked at
That ties the merged #569 row (65,000) again, so this isn't merged (follow-ups are merged only when they beat the merged row). The leaderboard keeps the #569 row and the footnote now lists this run too. The head moved to — benchmark agent |
Two hardening items from the ladder-scale analysis: 1. GENERATION WRAP (latent correctness bug): next_generation was a 16-bit wrapping counter — at 65,536 admits it wrapped, and a stale in-flight CQE could collide with a live connection's generation and be misrouted (wrong fd closed/written). arjay's 65k-user ladder run churned through the wrap window. uring-kit 0.1.4 widens the token generation field to 24 bits (16.7M admits per wrap; the 16-bit slot still fits fds exactly under NOFILE=65535). 2. fd-in-token routing: the token's (previously unused) slot now carries the connection fd — every CQE routes straight back to its connection with zero lookups. The gen->fd HashMap is gone (one hash per CQE saved), and the live-vs-graveyard decision is a single generation-checked conn lookup. Also: the graveyard accounting now clears op_in_flight BEFORE close_conn on error paths (the completing CQE IS the in-flight op — the old order left pending_ops=1 forever, leaking graveyard entries on every recv error). test: 42/42 golden; uring-kit 43+8+1 tests; rig-verified.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Benchmarked at
That's below the merged #569 row (65,000), so this isn't merged. The leaderboard keeps the #569 row and the footnote now lists this run too. The head moved to — benchmark agent |
…arvation) The side-thread checkpoint experiments both failed at 7% write failures (16k VUs): a PASSIVE checkpoint folds wal frames but never shrinks the WAL FILE — the file-size gate stayed open after the first checkpoint and the thread checkpointed back-to-back every 200ms, holding the wal-index write lock against the writer's frame appends. Likes (17% of traffic) starved; the write-gate coordination flag didn't help because the gate itself was the bug. Reverted to the verified-best policy: the native on-writer autocheckpoint at 1000 pages (~4MB) — 0.69% errors at a 16k-VU hold, WAL bounded, read latency stable. Its known cost: the checkpoint's DB fsync runs on the event-loop thread (the ~0.7% feed timeouts, under the 1% gate). The kensac-style off-loop checkpoint thread is the documented next step, and it needs a lock-aware trigger (the checkpoint result's log-pages count, not the file size). test: 42/42 golden.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Benchmarked at
That's below the merged #569 row (65,000), so this isn't merged. The leaderboard keeps the #569 row and the footnote now lists this run too. Also, the server returns occasional 500s on The head moved to — benchmark agent |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Benchmarked at
That's below the merged #569 row (65,000), so this isn't merged. The leaderboard keeps the #569 row and the footnote now lists this run too. Push a new commit and it gets queued for another run. The 500s on POST /posts (a handful per run since — benchmark agent |
… = torn-page corruption The bisect result: with mmap_size=1GB (the CL-013 perf change), the native autocheckpoint's fold rewrote DB pages in place while mmap readers served those same pages — the WRITER's own mmap'd copies went torn mid-fold (its INSERTs failed with 'database disk image is malformed', 7% of likes at 16k VUs) and the shim's mmap-backed pcache entries served torn bytes to the cursors. Reproduced across four consecutive runs; with mmap_size=0 on both connections and the same everything else: 0.00% malformed, 0.109% errors at a 150s 16k hold, post-hold integrity OK, likes exactly accounted. The cost: page reads via pread+pcache instead of zero-copy mmap (the rep_movs share returns, bounded by the pcache hit rate). Correctness first; the latency delta on arjay's fast storage is the ladder's to measure. Also ships the LOOP_STATS instrument (queue depth, pass duration, cycle rate per 5s) — the tool that caught the post-crash collapse live (conns=15999, completions at 1-10/s, then k6 teardown).
The live profile at 16k VUs ranked the allocator at ~5.5% (_mi_page_ malloc_zero 3.3% + mi_free 1.3% + theap 0.6%): every feed allocated a fresh 6KB body buffer per response, and every write completion dropped it. The loop is single-threaded — a plain Vec free-list (take_body / return_body around the outbox frame lifecycle) recycles the buffers with zero locks. Bodies move into outbox frames as before; the frame returns its buffer to the pool on write completion (after the kernel is done with the bytes — the CQE marks completion). test: 42/42 golden.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Benchmarked at
That's below the merged #569 row (65,000), so this isn't merged. The leaderboard keeps the #569 row and the footnote now lists this run too. Push a new commit and it gets queued for another run. The 500s on POST /posts are still there (21 in the 5-minute hold). — benchmark agent |
…s fold era corrupted the DB The rig evidence across this session: (1) with wal_autocheckpoint=1000 the WAL reached 30,993 pages without a single fold firing (a manual PASSIVE checkpoint from an external connection folded all 30,993 cleanly, busy=0 — the mechanism works, the trigger never fired in our usage); (2) the checkpoint-thread designs starved the writer (7% like failures); (3) the corrupt-era runs left the seed.db file corrupted (torn pages, cause unresolved — the VM hard-crash and the checkpoint era are both suspects). No checkpointing verified clean: 0.137% errors at a 150s 16k-VU hold, integrity ok on six during-hold samples and post-hold, likes exactly accounted. Cost: the WAL grows across a hold (reads pay wal-index lookups over its frame set — med 1.3s / p95 7.2s on the slow VM storage). The checkpoint redesign (off-loop, lock-aware trigger) is documented in the ledger before it comes back.
…he pragma entirely — sqlite's default 1000 silently re-enabled the corrupting fold)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Benchmarked at
That ties the merged #569 row (65,000), so this isn't merged (a follow-up has to beat the merged row). The leaderboard keeps the #569 row and the footnote now lists this run too. Push a new commit and it gets queued for another run. — benchmark agent |
The checkpoint redesign, third attempt, informed by the two failures: - CL-014b lesson 1 (unconditional thread): the checkpoint's copy phase holds the wal-index write lock and stalls the writer's frame appends. - CL-014b lesson 2 (the file-size gate): a PASSIVE checkpoint folds frames but never shrinks the WAL FILE — the gate never closed. - CL-013 lesson (the native autocheckpoint): its fold never fired at all (30,993 pages unfolded), and its fold-era DB writes raced the shim's mmap pages (mmap since removed). The design that resolves all three: the shim's read txn CLOSES at the pass boundary (end_pass — new ShimReader split), the WRITER runs PRAGMA wal_checkpoint(TRUNCATE) in that reader-free window when the WAL file exceeds 16MB (stat — no DB locks; TRUNCATE always succeeds with no readers and resets the file to zero), then the shim's read txn + cursors reopen. The WAL stays bounded at ~16MB + one pass, the wal-index stays small (fast reads), the fold is sqlite-native from the writer connection, and no reader can observe a torn page (no reader txn is open during the checkpoint). test: 42/42 golden.
…es the torn-read hazard structurally The mmap=0 bisect cost the read path ~500x at the median on the slow VM storage (med 2.7-6.7ms with mmap vs ~1,300ms without — every scattered page read became a storage pread). The torn-read hazard that forced the bisect is eliminated STRUCTURALLY by the reader-free checkpoint window (the previous commit): checkpoints run only when this connection's read txn is closed, so the mmap can never observe a fold mid-read-txn. The writer's mmap stays 0 (its fold writes must not tear its own pcache — CL-015).
The two failed designs (CL-014b) + the never-firing native autocheckpoint all triangulated to this design: - TRUNCATE every 2s from a side connection: the fold copies only up to the oldest reader mark (the shim's per-pass txn advances it every cycle), so each checkpoint copies ~2s of writes (~1-2MB, ~ms) and the WAL FILE resets to zero on success — bounded, and the stat-gate trap from v2 (PASSIVE never shrinks the file) is gone because TRUNCATE does. - busy_timeout 0: if the loop holds locks, the checkpoint SKIPS (never stalls the loop — the v1 failure). - The TRUNCATE only completes between passes (no reader txn open), so no reader can observe a torn fold. The corruption chain this closes: the never-firing native autocheckpoint let the WAL reach 30,993 pages; the fold-era DB writes raced the shim's mmap pages (torn reads -> 'malformed' -> SQLITE_CORRUPT on the writer's inserts); the vm hard-crash then mid-checkpoint sealed a torn page-1 into the file. test: 42/42 golden.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Benchmarked at
That ties the merged #569 row (65,000), so this isn't merged (a follow-up has to beat the merged row). The leaderboard keeps the #569 row and the footnote now lists this run too. The head moved to — benchmark agent |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Benchmarked at
That ties the merged #569 row (65,000) again, so this isn't merged (a follow-up has to beat the merged row). The leaderboard keeps the #569 row and the footnote now lists this run too. The ceiling still looks like the connection resets at ~68k with CPU well below 100 %, rather than the checkpointing. — benchmark agent |
…low arjaythedev#569) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
arjaythedev#569) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow-up to #569 (merged at 65,000 — thank you). The run showed the wall moved to CPU: 100% at 145 µs/req. This PR is a callgrind-guided cut of the shim read path's per-request instructions (-29% measured):
Measured: 231M -> 164M Ir per feed-25 + post-get + parse iteration on the seed (callgrind, same box); rig at 16k VUs: req/s 875 -> 2,849, p95 2.13s -> 74ms, 0.00% errors (0/175,995); 42/42 golden; 15/15 unit incl. the new escape parity.