Problem and how it was found
The question was where about 130 ms of a roughly 167 msPOST /sandboxes went, given that a cold boot benchmarked at around 34 ms. The per-phase profile (instrumenting every step of create_sandbox_cold and Vm::boot, then 20 sequential creates with each sandbox destroyed before the next) is described in the rootfs reflink post. It was driven with:
vm boot phase breakdown debug event splits Vm::boot into its steps. Over the 20 creates, the mean Vm::boot was 34.00 ms and divided as follows:
The socket wait stood out for a reason beyond its size. Across all 20 boots it measured 20.11 ms with a minimum of 20.04 ms and a maximum of 20.18 ms. Real waiting has spread. A spread of 140 microseconds around a round 20 ms is the signature of one quantized sleep: the code checked, failed once, slept 20 ms, and then succeeded on the second check every single time.
Root cause
wait_for_socket polled for Firecracker’s API socket file with a fixed sleep:
exists() check ran immediately after spawn, usually before the socket file existed, so the loop slept 20 ms, and the second check always found it. The overshoot, roughly 19.4 ms per boot, was dead time. A fixed poll interval is the wrong tool for a race whose duration is far shorter than the interval.
There was a trap in the obvious fix. Making the existence poll faster would have been wrong, for a reason about how Unix sockets work. The socket file appears when Firecracker calls bind(), and it only accepts connections after listen(). Between those two calls the file exists but a connect() fails with ECONNREFUSED. A fast existence poll can win that race and hand the caller a socket that is not ready yet.
The change
The fix retries the connect itself, not the existence of the file. If the thing you need is a successfulconnect(), polling for connect() has no window in which the check passes and the next step fails. The helper is retry_with_backoff at core/crates/vmm/src/vm/mod.rs:282:
connect_api_with_retry at core/crates/vmm/src/vm/mod.rs:311:
Vm::boot is core/crates/vmm/src/vm/boot.rs:200, with a 2 second timeout, and snapshot resume reaches the same helper from core/crates/vmm/src/vm/snapshot.rs:85, so resume gained the same saving.
Three unit tests in core/crates/vmm/src/vm/mod.rs pin the behavior:
The sibling bug
After the fix, the codebase was audited for the same pattern.Vm::call, Vm::open_pty and Vm::open_exec_stream each retried a failed vsock connection on a flat sleep(100ms) for up to five seconds. That is five times the per-retry cost of the socket bug. The three near-identical loops were replaced with the same helper:
Result
The API-socket fix was measured with the same method as the baseline, in two sets of 20 creates:
That is about 19.4 ms off every boot and about 23 ms, or 14%, off every cold create, with the rest of the improvement beyond the socket wait itself unexplained (see below). Snapshot resume got the same saving, since it shares the helper. The socket really is ready in under a millisecond; a boot is now bounded by actual work, mostly
InstanceStart.
Two numbers moved that are not attributed to the change. InstanceStart read lower afterwards (11.87 ms before, 8.75 and 9.13 ms after). It was not the target and is not confidently attributed to this change. And the boot dropped by about 22.7 ms while the socket wait dropped by about 19.4 ms, so about 3 ms of the boot improvement came from elsewhere in that run.
The load test (scripts/load-test.sh, 4 workers, 5 cycles each) saw the create mean move too, from a 369 ms mean to 211 ms at 4 concurrent workers, though throughput stayed flat because a cycle also contains exec and delete. See the performance model post for why a cheaper phase does not always make a cycle faster.
The sibling fix showed no end-to-end change
TheVm::call fix was A/B tested old against new. The test timed a fresh sandbox’s first real exec, end to end, by revert-and-remeasure. Both versions measured about 420 to 460 ms. They were indistinguishable within noise.
The fix is real and correct, because the worst-case overshoot per retry dropped from roughly 100 ms to roughly 20 ms. It does not show up end to end because that 420 to 460 ms is dominated by something else entirely: the guest’s own startup. The kernel finishes booting, init runs, and the guest agent starts and binds its vsock listener. Until that happens the host’s retries fail no matter how fast they are, so shaving the retry overshoot only changes how soon after the agent starts the host notices. With the old 100 ms sleep the host noticed within 100 ms of the agent coming up, and with the new backoff within 20 ms, and a few tens of milliseconds disappear into a measurement of several hundred.
This turned the real finding around. Every exec after the first took 3 to 5 ms, which proved the 420 to 460 ms was a one-time “is the guest agent listening yet” cost paid silently by whichever caller made the first request, and mislabeled as “exec is slow”.
POST /sandboxes returning 200 means Firecracker’s InstanceStart succeeded, and nothing before this measurement had counted through to the agent answering. A sandbox forked from an already-warmed snapshot paid about 4 to 18 ms for its first exec, so the gap pre-warmed pools close is far larger than a create-latency comparison suggests. scripts/bench-report.sh now tracks first_exec_client and first_exec_resumed so that is visible permanently.
What it cost or risks
- More wakeups in the worst case. A tight early backoff polls more often than a 20 ms sleep. The cap bounds this: the API-socket loop settles at 5 ms intervals and the vsock loop at 20 ms, against a 2 second and 5 second budget. The extra work is a handful of failed
connect()calls, each cheap. - A different failure shape. The old code could only fail with “never appeared”. The new one fails with “never accepted a connection within” the timeout, plus the underlying error, which is more informative, and the
TimedOutkind is asserted by a test. - No change to the guest agent wait. The fix removes dead sleep. It does not make the guest agent start faster. The 420 to 460 ms first-exec cost is still there and is the larger number. (It was later cut to about 214.5 ms by tuning the guest kernel command line; see Guest boot time.) Whether
create()should block until the agent has answered once, so that 200 means “ready”, is an API question that has not been decided. - A caveat on attribution. The unexplained roughly 3 ms in the boot improvement and the lower
InstanceStartreading are reported as observed. They are not claimed as consequences of this change. - Boot numbers have since shifted. Criterion on 2026-11-24 (kernel 6.8, same box) read cold boot at 12.6 to 14.0 ms, against 10.5 to 10.9 ms in the earlier published run. Both are real readings under different kernel and load conditions, and neither is authoritative.
How to reproduce
Needs the remote dev box with real Firecracker. To see the socket wait itself, read the debug event:socket_wait_us across the 20 events. On the old code it sat between 20,040 and 20,180 microseconds; on the current code it should be well under a millisecond (0.67 and 0.69 ms means in the measured runs). To reproduce the sibling measurement, run scripts/bench-report.sh 20 and read first_exec_client and first_exec_resumed. To compare old and new Vm::call yourself, check out the commit before the helper was introduced, rebuild, re-run the same report, and expect the first-exec number not to move.