Skip to content

perf(clone): hand post-resume reseed to a detached child - #175

Merged
CMGS merged 4 commits into
masterfrom
perf/detached-reseed
Jul 29, 2026
Merged

perf(clone): hand post-resume reseed to a detached child#175
CMGS merged 4 commits into
masterfrom
perf/detached-reseed

Conversation

@CMGS

@CMGS CMGS commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Problem

Every vm clone / vm restore ends with a synchronous vsock reseed of the guest CRNG. The dial cannot complete until the resumed guest wakes up and schedules the agent's accept loop, which costs tens of milliseconds — and grows with snapshot age (fresh snapshot ~11ms, 20-minute-old ~27-36ms). On a bare-metal testbed this was 35-50ms of a 55-90ms clone wall: the single largest cost on the clone path, ahead of the CH restore itself.

Warm-pool refill workloads clone long-lived golden snapshots, so they always pay the aged-snapshot path.

Change

reseedAfterResume now re-execs cocoon vm reseed as a session-detached child (Setsid) instead of dialing inline:

  • Same best-effort contract: the reseed lands at the same absolute time post-resume; only the CLI return advances. Spawn failure falls back to the inline path.
  • Resolved --root-dir/--run-dir/--log-dir travel as explicit flags, so file- or flag-configured parents behave the same as env-configured ones.
  • Windows guests and vsock-less VMs keep the existing inline handling (skip + warn).

Numbers (bare-metal, CH v54.0.0, 2c/1G snapshot, same host back-to-back)

metric before after
sequential clone, no NIC 52-65ms 23-30ms
sequential clone, --bridge 66-87ms 27-36ms
burst-16 clone wall 341-356ms 150-166ms

Verified after the change: 16/16 burst clones agent-healthy; hot-swapped NIC up in the guest with a fresh MAC; detached child visible re-parented to init and exiting within 1s; spawn-failure fallback exercised. Dual-GOOS lint clean, tests green on darwin and linux.

CMGS added 4 commits July 29, 2026 03:13
The synchronous vsock reseed after vm.resume waits out the guest's
wakeup (tens of ms, growing with snapshot age) and dominated every
clone/restore wall: 55-90ms observed, of which 35-50ms was the reseed
dial+rpc. Re-exec cocoon vm reseed as a session-detached child instead;
the reseed stays best-effort with the same landing time, only the CLI
return advances. Resolved dirs travel as explicit flags so file- or
flag-configured parents behave like env-configured ones. Spawn failure
falls back to the inline path.

Bare-metal A/B (CH v54, 2c/1G snapshot): seq clone 57->23ms (none) /
77->30ms (bridge); burst-16 wall 356->150ms; 16/16 agents healthy,
hot-swapped NIC up with fresh MAC.
…ading verbatim copies

Every CH restore decoded and re-validated cocoon.json twice (preflight on
the source, AfterExtract on the merged runDir) although the file is copied
verbatim between the two; DirectClone likewise parsed config.json on the
source for COW classification and again on the runDir copy. PreflightRestore
now returns the validated meta and the clone copy step hands its parse to
cloneAfterExtractParsed, so each restore/wake and direct clone decodes each
file once. FC ignores the returned meta (it reads the record instead).
…ll helpers

Collection carried a store handle that nothing ever read, threaded through
NewCollection/NewRecordTx/NewNamedTx/tombstone.NewTable and every caller;
RecordTx shadowed its collection's ns/table. localfile Create/CreateFromDir
shared an identical 13-line lease+placeholder+rollback preamble, now
beginBuild; FC's lease-close loop and the CH/FC debug COW-prep block each
existed twice.
Approved cut-list from the LOC audit, all call-site-verified:
BaseHandler.Conf nil guards (provider wired unconditionally in root),
cloneFromDir/rollbackNetwork/relay-response nil checks (all callers
pass non-nil), gcTick's GC-nil clause (implied by GCInterval > 0),
the producer-less SnapshotFileSkip kind, and SnapshotMeta.CPU/Memory
(written by FC, read by nothing; old sidecars with the keys still
parse).
@CMGS
CMGS merged commit 3447d47 into master Jul 29, 2026
4 checks passed
@CMGS
CMGS deleted the perf/detached-reseed branch July 29, 2026 03:08
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.

1 participant