Skip to content

perf(controller): load the job catalog once per host observation - #395

Merged
kyle-sexton merged 1 commit into
mainfrom
perf/single-catalog-load
Sep 23, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
perf/single-catalog-load

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #394

Summary

While idle, every 5 s host observation fully read and strictly decoded jobs.json plus runner-assign-times.json 2N+1 times for N workers. That was 9 loads of 4.64 MB on melo-lap-001 and 19 loads of 2.72 MB on melo-desk-001. It accounted for about 75% of the laptop's remaining ~0.2-core idle CPU on v0.1.26, and about 87% on the desk.

Fix

  • enrichWorkerJobs: loads the catalog once and matches every worker against it.
    • ActiveJobLookup is now Load(ctx), which is already part of jobindex.Store.
    • The per-runner rule, including the tombstone rule, moved to Catalog.ActiveJob. FileStore.ActiveJob delegates to it, so there is one copy.
  • indexAdopted: loads once and pre-merges each patch with jobindex.Merge. It calls Upsert only when the key is absent, the merge errors, or the merged record differs.
    • Upsert still re-loads, re-merges and saves under the store lock, so writes mean exactly what they did before. The pre-merge only skips the full load a no-op Upsert would spend.
    • Keys are unique: Validate rejects duplicate pool/runner records. So the snapshot and Upsert always resolve the same record.
  • reconcileStaleOpen: reuses the catalog from adoption instead of loading again.
  • A steady-state idle observation now does 2 loads, whatever the worker count. The 24 h cleanup load is unchanged.
  • No change to the jobs.json schema, and no new dependencies.

Verification

  • TestStepLoadsTheJobCatalogIndependentOfWorkerCount: a real Step with 1 and with 8 busy workers performs the same, non-zero number of Load calls.
  • TestAdoptAndCleanupLoadsTheCatalogOnceIndependentOfContainerCount: with a real FileStore, a repeat adoption of 1 or 8 containers does exactly 1 Load and 0 Upsert. A new container adds exactly 1 Upsert, and its record is open.
  • All of these exit 0:
    • go build ./...
    • go test ./...
    • go test -race ./... (Linux, WSL)
    • golangci-lint run ./... (v2.13.1)
    • CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath ./cmd/...
  • Idle CPU on melo-lap-001 gets re-measured after the next release. The estimate is ~0.2 core down to ~0.05–0.08; that is a judgment from the measurements, not a measured result.

Related

🤖 Generated with Claude Code

An idle observation read jobs.json and its sidecar 2N+1 times for N
workers: one ActiveJob load per worker, one Upsert load per adopted
container even when the merge was a no-op, and one stale-open load.

enrichWorkerJobs now loads the catalog once and matches every worker
through Catalog.ActiveJob, which FileStore.ActiveJob shares. indexAdopted
loads once, pre-merges each patch, and calls Upsert only when the record
would change; Upsert still re-merges under the store lock. The adopted
catalog it returns feeds reconcileStaleOpen, so a steady-state tick costs
two loads regardless of worker count.

Refs #394

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T20:10:21.362481Z 5759eb1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kyle-sexton
kyle-sexton merged commit fbd3c51 into main Sep 23, 2026
2 checks passed
@kyle-sexton
kyle-sexton deleted the perf/single-catalog-load branch September 23, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(controller): idle observation re-reads jobs.json 2N+1 times per reconcile tick

1 participant