Repository navigation
Description
Summary
sockwait — the wait for Firecracker's API socket to appear after the jailer starts — is 38.07 ms of a ~47 ms restore at 64 slots, and 869 ms at 256 slots. It is the dominant cost of a restore and therefore of the pool's replenishment rate, which is what now bounds throughput.
This is not the quantization artifact #304 addressed. #304's fix was correct and is merged (#315), but it only removed the polling granularity; the underlying wait is real, and it is much larger than that issue's framing implied.
Measured on srv-r16b14s16 (bare metal, 72 cpu / 754 GiB, governor performance, swap off), one worker, merged main with pooled cgroups (#319), via SH_DIAG_PHASES.
The measurement
restore phases, mean per restore:
| slots | prep |
wsimg |
jailer |
sockwait |
loadsnap |
restore total |
|---|---|---|---|---|---|---|
| 64 | 0.62 ms | 0.25 ms | 2.18 ms | 38.07 ms | 5.56 ms | ~46.7 ms |
| 128 | — | — | 2.91 ms | 238.72 ms | 8.02 ms | — |
| 256 | — | — | 4.14 ms | 869.43 ms | 11.47 ms | — |
p50 tracks the mean closely (34.47 / 235.96 / 858.40 ms), so this is not a tail effect — it is where the distribution sits. n = 25,985 / 51,969 / 103,937.
It degrades 23x from 64 to 256 slots, far worse than linearly, while jailer (the fork/exec itself) grows only 1.9x and loadsnap 2.1x.
Why this is not a polling artifact
waitForUnixSocket polls at socketPollMin = 250us growing to socketPollMax = 1ms (launcher_firecracker.go), so the resolution is 1 ms or better throughout. A 38 ms reading means the socket genuinely was not there for ~38 ms.
This was A/B tested during the campaign and the poll cap was explicitly falsified as a throughput cause — raising the cap changed nothing. That result stands; it just means the remaining time is real work rather than sleep.
Worth stating plainly because it contradicts how #303 and #304 have been cited: "90% of a restore is a fixed 20 ms poll" was true of the instrument, and the reading was quantized to the 20 ms quantum. With fine-grained polling the true value is larger than 20 ms at the operating point, not smaller.
Why it matters
- This is plausibly the mechanism behind "the replenishment rate", which is the campaign's remaining bound. Every restore pays
sockwait, replenishment is restores, and throughput peaks at 64 slots because demand outruns the rate the pool can restore VMs (Acquire4.30 → 281.20 ms and true cold rate 0.142 → 0.698 across the same range). - It would explain why a second worker process does not help. Two workers at the same total slot count deliver 1.00x (580.58 vs 580.60) while host CPU stays at 66–73%. If what serialises is kernel-side process bring-up, both processes contend for the same thing, which is consistent with a host-wide bound that scale-out cannot relieve.
- Together with vmpool: Destroy is still ~55% of every Exec, and 89% of it is cmd.Wait (SIGKILL to reap) #307's
cmd.Wait(58.94 ms, 89% of Destroy), the two dominant remaining costs are both process lifecycle rather than work. The command itself is 6.2 ms.
What to investigate
- What is Firecracker doing for those 38 ms before it binds its API socket? Under the jailer, with
--cgroup-version 2 --parent-cgroupand aMAP_SHAREDpinned memfile. Candidates: the jailer's own chroot/pivot_root and mount setup, seccomp filter installation, the binary's dynamic-link and init path, or simply CPU starvation at 47 of 72 cores busy. - Is it CPU starvation or serialisation? The 23x degradation across a 4x slot range is a queueing signature, but host CPU is flat at 66–70%, so it is not simple saturation. A
perf/stracepass on one restore under load, compared against an idle restore, should separate these. - Does it scale with VM count or with restore rate? Distinguishable by holding slots fixed and varying
ITERS_PER_SLOT. - Is the socket wait avoidable at all? If Firecracker can be given a pre-bound socket (inherited fd) rather than creating its own, the wait disappears by construction. Worth checking what the API supports.
Relationship to #274
If per-Exec VM lifetime lands, a VM serving several Execs pays sockwait and cmd.Wait once per session instead of once per command. That does not make this issue moot — a lower restore cost raises the replenishment rate for any lifetime policy — but it does mean the two should be sequenced deliberately rather than pursued independently.
A caution on the arithmetic
restore phases is logged for every restore, including background replenishment, while exec phases's resume_us is per Exec. These are different populations and must not be summed: at 64 slots sockwait (38.07 ms) exceeds per-Exec resume (32.50 ms), which is not a contradiction — most Execs pop a warm standby and never wait for a socket. sockwait bounds the rate at which standbys can be produced, which is the constraint, rather than being a term on every Exec's critical path.
References
- Sub-phase data and the campaign context:
docs/notes/2026-09-22-exec-throughput-campaign-results.md(PR docs: publish the Exec/s campaign results and preserve #303's ruled-out candidates #327) waitForUnixSocketand the backoff:remote-worker/internal/vmpool/launcher_firecracker.go- Refs e11: the restore path does not serialize — 90% of a restore is a fixed 20ms poll, and the c>=16 knee is downstream #303, vmpool: waitForUnixSocket's fixed 20ms retry is 90% of every restore (TDD) #304, vmpool: Destroy is still ~55% of every Exec, and 89% of it is cmd.Wait (SIGKILL to reap) #307, P4 microVM tier: per-
ExecVM lifetime is finer-grained than the design needs — worth a separate architecture pass #274
Activity
pdettori commentedon Sep 22, 2026
Root-caused: it is the JAILER, not Firecracker — and two numbers in the issue body are wrong
Three measurements on
srv-r16b14s16, idle host except where stated. Correcting this issue's own figures first, then the mechanism.Correction 1 — the 38.07 ms figure was inflated by host state
A clean ladder (
drop_cachesbefore every rung, dying cgroups verified 0 at every rung start, slots pinned at 64 so only load varies) gives:So at 64 slots it is 22–25 ms, not 38.07. The original figure came from a sweep where caches were dropped once at the start and dying cgroups had accumulated to ~1000 — host state, not
sockwait. Drift check on the repeated rung: +1.3%.The 238.72 / 869.43 ms figures are also mislabelled: those were at 128 and 256 slots, i.e. over-subscription past the throughput peak, a different configuration rather than the same configuration under more load.
Correction 2 — sockwait is U-shaped, and only about half of it is contention
It minimises at c=8 (9.78 ms mean / 6.76 ms p50) and rises in both directions. The decisive row is
c=1: with the host at 1.8% CPU and nothing to contend with,sockwaitis still 16.73 ms. I checked for cold page cache from thedrop_caches— the 87 values run 29.9, 18.7, 13.0, 16.8, 18.8, 19.2 … 21.5, 14.7, 14.8, 18.5, 16.2, 20.5, so only the first is elevated and there is no decay. The floor is real.Reading it as components: an irreducible floor around 7 ms p50, a load-dependent increment (c=8 → c=64 nearly doubles it), and a rise at near-idle whose cause is not established (plausibly CPU idle-state exit latency, untested).
The mechanism: 82-85% of the pre-socket window is the jailer
strace -f -tton the jailer, splittingexecve(jailer)→execve(firecracker)→bind():mount)mountx2,pivot_root,mknodx4 (/dev/net/tun,/dev/kvm,/dev/urandom,/dev/userfaultfd)execve->bindCorroborated without strace, same idle host: bare Firecracker binds in 2.87-3.14 ms against a harness floor of 2.44 ms (each
date +%s%Nis itself a fork+exec), while the jailed path takes 7.4-7.6 ms. Consistent with the traced split.Firecracker is not slow. It binds its socket in ~1.5 ms. The wait is the jailer building a fresh chroot per VM.
Absolute values are inflated by ptrace overhead, but the split is measured within single runs and is corroborated by the untraced comparison, so the 82-85% share is the robust part.
This is also an instrumentation bug in our own phase accounting
The
jailerphase reads 0.34-1.62 ms across the whole ladder because it is measured astime.Sinceaftercmd.Start()returns — i.e. it times fork/exec returning, not the jailer's work. All 6-8 ms of chroot construction happens after that and lands in thesockwaitbucket.That mis-attribution is why this looked like "Firecracker is slow to bind" for two rounds of analysis. Worth splitting
sockwaitintojailer_setup(until the jailedexecve) andfc_bind, so the field names say where the time is.What this changes about the fix
--no-apiis dead. Tested directly:--config-filerequiresdrivesandboot-sourceand then asks for the kernel image — it is a fresh-boot config, and asnapshotkey is silently ignored (unknown fields are not rejected). Snapshot restore is API-only in v1.17.0. Separately, we need the API twice:PUT /snapshot/loadand laterPATCH /vm {state: Resumed}, since standbys are deliberately left paused.The promising direction is pooling the jail, exactly as #319 pooled the cgroups. The per-VM work the jailer repeats — create the chroot dir, bind-mount,
pivot_root, fourmknods — is the same class of per-VM kernel/filesystem churn that cost 195.52 ms per Destroy until it was pooled. Options worth costing:cgroupPooldoes, so the chroot and its device nodes are created once and rebound rather than rebuilt.pivot_root/mknodsetup ourselves against a pre-built template, keeping the isolation properties but not the per-VM construction.mknods are needed —/dev/net/tunin particular, given this launcher never issuesPUT /network-interfacesand standbys are headless by construction.Option 3 is the cheapest to test and option 1 has a proven precedent in this codebase.
Relationship to #274: unchanged in direction but weaker in isolation. #274 amortises the whole restore across a session, which still helps. But since most of this cost is our own per-VM setup rather than an inherent VMM property, it may be removable outright — which would be worth more than amortising it, and would compose with #274 rather than competing.
[-]vmpool: sockwait is 38ms of a restore at 64 slots and 869ms at 256 — the 20ms poll fix removed the quantization, not the wait[/-][+]vmpool: the pre-socket wait is 82-85% JAILER chroot construction, not Firecracker (which binds in ~1.5ms)[/+]pdettori commentedon Sep 22, 2026
The three options are now one: option 3 is unavailable, option 1 is validated (~2x)
Two cheap tests on
srv-r16b14s16narrow this considerably.Option 3 (drop
/dev/net/tun) — NOT AVAILABLEjailer --helpon v1.17.0 exposes no device-node control. The fourmknods are hardcoded, sodropping tun would mean patching or replacing the jailer rather than configuring it. Off the table
as a cheap win.
Option 1 (pool the jail) — VALIDATED, and it halves the pre-socket time
The jailer reuses an existing jail directory rather than refusing it. Same
--id, threesequential runs, idle host, time from
execve(jailer)to the API socket being bound:~4.3 ms saved per restore, about half the pre-socket window, and 4.0 ms is close to the
~2.9 ms bare-Firecracker floor (measured against a 2.44 ms harness floor). The saving is presumably
the chroot construction and the exec-file copy that reuse skips; the
mknods appear to be thecheaper part.
What a reused jail leaves behind, i.e. what a pool would have to reset:
The device nodes can stay.
api.sockandfirecracker.pidare per-VM residue.Two things to get right, and one is a security question
cgroupPoolhandles the analogous risk by refusing to reuse a cgroup with a process still in itand counting that as a leak rather than reusing optimistically; a jail pool needs the equivalent,
plus an explicit decision about what must be removed before reuse. This is the part that deserves
care — it is the only place in this issue where a performance change touches isolation.
verify-on-pop, exactly as
cgroup_pool.godoes, and the same "never reclaim a name after afailed mint" discipline (perf(vmpool): reuse per-VM cgroups from a pool instead of creating one per VM (#258) #319 review).
Prerequisite: fix the phase split first
The
jailerphase currently measurestime.Sinceaftercmd.Start()returns — fork/execreturning, not the jailer's work — so all 6-8 ms of chroot construction lands in
sockwait. Anyfix here will be measured with that blind spot unless
sockwaitis first split intojailer_setup(until the jailed
execve) andfc_bind. That mis-attribution already cost two rounds of analysischasing "Firecracker is slow to bind"; it should not also obscure the fix.
Revised recommendation
cgroup_pool.go, with the residue policy decided explicitly.what it does to the load-dependent half, which this test does not address.
Option 2 (skip the jailer entirely) drops in priority — option 1 gets most of the win without
reimplementing isolation.
pdettori commentedon Sep 22, 2026
Handoff note for whoever picks this up: PR #331 (
docs/notes/2026-09-22-328-jail-pooling-handoff.md).It pins the order of work (phase-split first, because it is the instrument for measuring the fix), the residue/isolation decision to settle before writing the pool, what to measure afterwards (floor and slope), the three dead ends with their evidence, the two corrected figures from this issue body, and the rig gotchas — including the one that cost a full ladder in this session.
docs(vmpool): the jail pool is a ~9% throughput REGRESSION; do not me…
feat(vmpool): split the pre-socket window at the jailed execve (rosso…
docs(vmpool): record why pooling the Firecracker jail was rejected (r…
fix(vmpool): make the phase split correct where it is built, not by o…
Merge pull request #332 from pdettori/feat/328-jail-pooling
docs(metal): record four measurement traps that each cost a wrong or …