← Blog2026-11-26
Creating a sandbox in 163 ms: the pipeline behind a fast cold start
A create returns in 163–169 ms p50 from Singapore — standby disks, a prefetch map per template build, and node warm-up took it down from ~310 ms.
Creating a sandbox means: find or make a guest image, wire up a disk, boot a VM, and wait until the agent inside it answers. Our create path now returns in a p50 of 163–169 ms measured from a client in Singapore — under the 200 ms line we set ourselves — down from about 310 ms for the same 2 vCPU / 1 GiB sandbox. Resume was the subject of the previous post; this one is the other half of felt speed: creation.
The path, measured
A create has three parts: the API (auth, template lookup, the database write — about 8 ms), the network (the ingress and the cluster hop, about 20 ms on a fresh connection, plus a 17 ms TLS handshake), and the orchestrator's Create, about 173 ms. Inside Create, envd-init — the guest booting far enough that the control daemon answers — is the dominant stage at ~124 ms; the VM launch itself is ~41 ms; loading the snapshot map ~5 ms. Everything else is small change.
Every fix below attacked one of those stages. All numbers are measured on the production bare-metal node, p50 / p90.
Disks on standby
A sandbox's root filesystem is served over NBD: connecting the device, through the kernel's netlink interface, costs ~100 ms across three queue freezes, and the connection is serialized inside the kernel. We keep a pool of already-connected NBD devices per node; a create only binds the right rootfs to a free device instead of connecting a new one. Getting the pool right took a few iterations: reclaims used to stall behind netlink and synchronous teardowns, so a hundred sequential creates had a tail of ~1,154 ms; parallel checking with liveness tested through sysfs and asynchronous teardowns brought the tail to ~195 ms. The pool refills to "target minus free", grows to the take-out peak of the last ten seconds, and decays after ten idle minutes.
The consequences show up under bursts. A 20-create wave on a warm pool finishes at p50 ~221–283 ms; on a cold pool — after a node restart or a long idle — devices the pool doesn't have are connected on the spot at 0.5–1.2 s each. Raising the pool depth from 10 to 20 put the miss count of a cold 20-wave at zero, worst case 572 ms. A wave arriving after the rootfs class has been idle longer than the decay window still pays for cold connections; that's the remaining sharp edge.
On top of that, each node warms up when it starts: the eight most-used template builds get their rootfs prefetched and the bind pool filled before the node reports ready. The first create of a template after a restart went from ~2,400 ms to ~310–336 ms — a cold start of the node is now only slightly slower than a normal create.
Knowing what the guest will read
Booting a guest touches only some of its rootfs pages. We record which regions each template build actually reads — a prefetch map, about 5,700 regions for the base template — so a create loads exactly those instead of discovering them by faulting. Two details made the map effective: regions marked as written are loaded writable, which removed most write-protect page faults entirely (1,112 down to 177 per create); and fills batch a window of neighboring pages — plus/minus 16 — because page use clusters, which shrank the faults a map miss costs from ~996 to ~480.
Page faults are fast only if the serving loop is fast. A write-protect fault used to cost ~80 µs because it dispatched to a fresh worker; parsing the common case inline brought it to ~18 µs — the same fix described in the resume post, shared between the two paths.
What's left
The honest breakdown of the remaining ~124 ms inside envd-init: the guest itself executes about 44 ms of vCPU time; it spends ~56 ms halted waiting on locks and timers — real idle the scheduler can't hide; and it loses ~33 ms touching pages the prefetch hasn't installed yet, because the map loads while the guest is already running. Prefaulting the page tables ahead of the guest would only save the ~11 ms of first-access faults on installed pages, which we measured and skipped.
| Case | Number | Where measured |
|---|---|---|
| Sequential creates | p50 163–169 ms, p90 187–189 | Production client, Singapore, daily |
| Create pipeline total, orchestrator | ~173 ms | Node traces |
| — of it envd-init | ~124 ms | Same |
| 20-create wave, warm pool | p50 221–283 ms, p90 ~291–320 | Same |
| 20-create wave, cold pool | 0 pool misses, worst 572 ms | After a restart |
| First create after node restart | ~310–336 ms; ~2,400 before warm-up | Same |
First node -v on a node template | ~461 ms; ~2,360 before | Same |
The next post covers the other axis: not how fast one sandbox starts, but how many fit on one node before anybody notices.