Skip to content

perf(workers): reduce reader memory on high-core hosts - #167295

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-worker-sizing-on-128-cores-20260919
Oct 8, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-worker-sizing-on-128-cores-20260919

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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 with availableParallelism() 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.

Combined workload Before After
Tracked workers 25 7
RSS after warm burst 2,180–2,205 MiB 769–775 MiB
Worker heap total 1,309–1,310 MiB 346–353 MiB
Warm burst wall time (240 requests) 6.66–7.15 s 2.33–2.67 s
Event-loop p99 during warm burst 90.5–113.0 ms 21.2–27.5 ms
Low-concurrency diff mean 107.9–109.2 ms 37.3–39.0 ms

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>, then node .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.

  • Blacksmith Testbox 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).
  • Candidate 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.
  • Focused pool, Git, state-reader, and Codex-history sibling suites: 135 passed across six routed shards in 56.19 s. Ten platform-specific cases skipped on Linux (eight macOS-native filesystem cases, two Bun cases).
  • 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.
  • Additional node scripts/run-vitest.mjs src/state/openclaw-state-read-source.test.ts on the benchmark lease: 5 passed in 27.51 s wrapper wall time. Total focused tests: 160 passed, 10 platform-specific skips.
  • Independent Codex review: scoped-clean through P2.
  • Hosted CI run 37799356150: passed on exact head 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 as 9932db4167dc65d8e12f7b503effd4506b3c6d1f.

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.

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.
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 8, 2026 15:16
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XS labels Oct 8, 2026
@steipete
steipete enabled auto-merge (squash) October 8, 2026 15:18
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 11:21 AM ET / 15:21 UTC.

ClawSweeper review

What this changes

The branch caps general-purpose reader pools at two workers through the existing sizing owner.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, correct performance change supported by meaningful production-component measurements, with confidence limited by harness-level scope.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): Copied runtime measurements exercise the changed sizing owner through compiled production Git and retained-state APIs with real workers, exact-output checks, and observed cleanup. They demonstrate component memory reduction on Linux with a 128-CPU sizing override; full Gateway and native high-core performance remain outside the claim. Raw linked logs were inaccessible to the reviewer. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes
User problem: Gateways on larger hosts can retain substantial worker memory after short bursts of reads.
Reason: The area owner proposes a small measured adjustment to their existing sizing policy. Component memory savings justify the change without introducing configuration or another scheduler.

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
Reviewed head: b6daa048858415865809d072681728d95ac69ee3

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The benchmark drives compiled production components directly; no complete Gateway or native 128-core before/after run is supplied. The body reports the intended baseline failures, but this read-only review did not execute them.
Agent review details

How this fits together

Worker 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]
Loading

Technical review

Best 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

Testing

Proof path: in-process harness. Added test files: 1.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced delta changes only the reader cap, four existing admission expectations, and architecture documentation; compute, serial, transcript, broker, and hashing policies remain intact. (src/infra/worker-pool-sizing.ts:11, b6daa0488584)
  • Current main still needs the adjustment: Fetched main retains the reader cap of eight. None of the three introduced paths changed between the merge base and fetched main. (src/infra/worker-pool-sizing.ts:12, 3e16525c4d67)
  • Sizing-owner history and accepted direction: perf(workers): centralize bounded worker pool sizing #167060 introduced centralized bounded sizing and explicitly preserved the shared-state two-worker minimum. Its author also proposes this measured capacity adjustment, providing area-owner direction. (src/infra/worker-pool-sizing.ts:17, b3196dfda335)
  • Production sizing consumption: The host supplies class capacity to the existing scheduler; numeric-only callers retain their existing contract. Shared-state pools obtain their numeric capacity from the sizing owner's preserved two-slot minimum. (src/infra/worker-task-host.ts:34, b6daa0488584)
  • Git process budget: Git content reads already share a two-process budget, independently of reader-isolate capacity; process settlement continues to release those slots. (src/infra/git-content-budget.ts:28, b6daa0488584)
  • Measured production-component behavior: The fully inspected PR body reports compiled Linux/Node 24.19.0 comparisons using real Git APIs and retained state reads, with sizing set to 128 CPUs on a four-CPU lease. Two runs per variant preserved exact outputs and completed worker cleanup; tracked workers fell from 25 to 7 and RSS from 2,180–2,205 MiB to 769–775 MiB. Increased saturated queue latency is explicitly accepted by the area owner alongside improved aggregate completion. Captured body source identity: b153a4c9bef66dcbdb968e4cc243c99b56a4306ff7759715c096741a27ff0cba. (b6daa0488584)

Likely related people:

  • Peter Steinberger: Raw commit b3196df adds src/infra/worker-pool-sizing.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b3196dfda335; files: src/infra/worker-pool-sizing.ts)

PR surface

Source -1, Tests 0, Docs +8. Total +7 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 2 -1
Tests 1 4 4 0
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 13 6 +7

Review metrics

Metric Value Why it matters
Reader capacity High-core cap: 8 → 2 workers per reader pool The change reduces maximum isolate fanout by 75% without adding a scheduling owner or operator setting.

Labels

Label changes:

  • add P2: This is a bounded memory-efficiency improvement with measured component benefits and no demonstrated urgent production outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This is a bounded memory-efficiency improvement with measured component benefits and no demonstrated urgent production outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

@steipete
steipete merged commit 9932db4 into main Oct 8, 2026
212 of 213 checks passed
@steipete
steipete deleted the steipete/perf-micro-worker-sizing-on-128-cores-20260919 branch October 8, 2026 15:40
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant