Repository navigation
perf(workers): reduce reader memory on high-core hosts - #167295
Conversation
Cap reader pools at two workers through the existing sizing owner, while preserving compute, serial, transcript, and SQLite broker policies. Keep the shared-state reader minimum needed by retained settlement reads. The compiled 128-core-shaped workload drops from 25 to 7 workers, saves about 1.39 GiB RSS and 960 MiB worker heap, and improves aggregate warm burst throughput 2.76x. The rig has four available CPUs; whole-Gateway production memory and native 128-core throughput remain unverified. Update the admission regression table and architecture documentation.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 11:21 AM ET / 15:21 UTC. ClawSweeper reviewWhat this changesThe branch caps general-purpose reader pools at two workers through the existing sizing owner. Review scores
ProductKind: Performance · Worth it: Yes Merge readiness✅ Ready for maintainer review This PR remains useful: current main retains the larger reader cap, and the narrow change preserves read-progress requirements. No actionable patch defect was found; the performance evidence supports component-level gains with clearly stated limits. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherWorker pools run Git operations, state reads, and other background tasks without blocking the Gateway. The host sizing policy determines how many worker isolates each pool may create. flowchart TD
A[Background read requests] --> B[Host sizing policy]
C[Available CPU count] --> B
B --> D[Reader pool capped at two]
B --> E[Shared-state minimum of two]
D --> F[Existing task scheduler]
E --> F
F --> G[Read results and worker cleanup]
Technical reviewBest possible solution: Keep the centralized sizing owner and reduce reader capacity while preserving retained-read progress and existing scheduler lifecycle contracts. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug reproduction; current source establishes the larger reader capacity, and the copied compiled benchmark demonstrates its component memory cost. Is this the best way to solve the issue? Yes. Adjusting the existing sizing owner is the narrowest implementation, and the unchanged shared-state minimum preserves the known retained-read progress requirement. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3e16525c4d67. Provenance checked
TestingProof path: in-process harness. Added test files: 1. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -1, Tests 0, Docs +8. Total +7 across 3 files. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment |
Cap reader pools at two workers through the existing sizing owner, while preserving compute, serial, transcript, and SQLite broker policies. Keep the shared-state reader minimum needed by retained settlement reads. The compiled 128-core-shaped workload drops from 25 to 7 workers, saves about 1.39 GiB RSS and 960 MiB worker heap, and improves aggregate warm burst throughput 2.76x. The rig has four available CPUs; whole-Gateway production memory and native 128-core throughput remain unverified. Update the admission regression table and architecture documentation.
What Problem This Solves
High-core Gateways can retain eight isolates in each reader pool after a brief burst, multiplying loaded code and caches even when steady-state queues are short.
Related: #167060.
User Impact
Caps general-purpose reader pools at two workers to reduce resident memory on larger hosts. The one-worker limit on hosts with one or two available CPUs is unchanged, and shared-state reads retain their two-slot minimum so a held settlement read cannot block a fresh catalog read.
Why This Change Was Made
Keep the existing sizing owner and demand-driven pool lifecycle. Reader and file-reader classes share a cap of two; compute stays at four and serial owners stay at one. Foreground transcript pools and the SQLite broker keep their separate policies. In particular, Git content already shares a two-process budget, so eight content reader isolates cannot run more Git commands simultaneously.
Production LOC delta: one deletion net (
1 insertion, 2 deletions), excluding tests and docs. No new scheduling layer, configuration option, schema, public API, dependency, module, or export.Evidence
Both variants were built from
38f444007f354ecb31760ea2c35807688e6b023d, differing only in the sizing owner. Compiled Linux/Node 24.19.0 rig, four available CPUs withavailableParallelism()overridden to 128 before importing the sizing owner. The same process runs real Git metadata/diff APIs and retained state reads against synthetic state. Each measured burst has eight concurrent requests per operation; eight warmup waves precede warm measurements. Two runs per variant, in candidate/baseline/baseline/candidate order, all pass exact-output and zero-live-worker cleanup assertions.This saves about 1.39 GiB RSS and 960 MiB worker heap, with 2.76× aggregate warm-burst throughput. Small state reads trade immediate dispatch for bounded concurrency: their warm-burst means range from 7.1–21.5 ms before to 11.2–11.9 ms after, and p99 from 31.9–204.1 ms to 31.2–34.5 ms. Aggregate worker-queue mean rises from below 0.01 ms to 45–53 ms in that saturated burst; overall completion improves. Low-concurrency queue means stay about 0.02 ms.
Benchmark provider: Blacksmith Testbox
tbx_01m4dzh7ztmrefc9grajt04126(run). Commands:node --import ./scripts/tsx.mjs .local/lane-652/build-proof.mts <baseline-mixed|candidate-mixed>, thennode .local/lane-652/<variant>/dist/readers-proof.js mixed <label>; final build/comparison/lifecycle-test command exited 0 in 128.62 s. Both isolated Git/state comparisons also passed output and cleanup assertions.tbx_01m4dysr87bgbrq4dxs9jq2b15(run): the revised admission table fails on the old policy in exactly four reader cases (eight workers admitted instead of two on 128 CPUs; seven instead of two on eight CPUs).pnpm test src/infra/worker-task-pool.preparation.test.ts --maxWorkers=1: 20 passed; 30.48 s wrapper wall time, including 28.02 s Vitest duration dominated by cold transform preparation.node scripts/check-changed.mjs --staged: passed, including production types, all 27 core-test type graphs, unused-export scans, lint (zero warnings/errors), schema/ownership guards, and remaining selected checks. Combined focused-test/gate command exited 0 in 37m27.59s.node scripts/run-vitest.mjs src/state/openclaw-state-read-source.test.tson the benchmark lease: 5 passed in 27.51 s wrapper wall time. Total focused tests: 160 passed, 10 platform-specific skips.b6daa048858415865809d072681728d95ac69ee3, with no failed jobs or reruns. Whole-workflow wall time was 1,387 s including queues; the final aggregate waited 385 s for its runner and completed in 8 s. Squash-merged as9932db4167dc65d8e12f7b503effd4506b3c6d1f.Limits: this is a 128-core sizing-policy test on a four-CPU lease, not a native 128-core throughput test or a complete Gateway workload. Returning a deployed Gateway to its earlier whole-process memory level remains unverified; the isolated memory reduction and aggregate latency improvement justify the bounded change.
Fixture corrections: the initial source-loader proof failed cleanup on esbuild's helper worker, so final comparisons use compiled workers. An initial report parser failed on diagnostic text preceding valid JSON; report extraction was corrected without rerunning those workloads. The final combined comparison and cleanup passed.