Our median CI job runs for about a minute, and before it runs it waits 28 seconds for a machine that did not exist when the job was queued. That wait is a third of what the developer sees.
This is the last of five posts about running each GitHub Actions job on its own EC2 spot instance. The first post covers the design. This one is about the boot: what it was, what it is, what we refused to pay to make it shorter, and what the machine is worth once it is up.
The version that booted in a minute
The first runner image was stock Ubuntu. The boot script installed everything on every boot: packages, the GitHub runner, its dependencies. It worked on day one, and from queue to start it took 63 to 68 seconds:
| Phase | Seconds |
|---|---|
webhook to RunInstances
|
7 |
| EC2 starts the instance | 5 |
| OS boot and cloud-init | 15–20 |
apt-get install |
20 |
| runner download and its dependencies | 10 |
| runner connects, GitHub assigns | 5 |
More than half of that was downloading the same things again. For a job that runs 51 seconds, the machine took longer to arrive than to do the work.
Bake it once
The fix is the obvious one: build an image with everything already on it. A pipeline rebuilds it every week from a shell script in the repository and publishes the new image ID to a parameter that the launch template reads at each launch. A rebuild rolls out with no deploy, and a bad image is rolled back by rewriting one parameter.
What goes in the image came from reading the step times of real jobs, one item at a time:
- The runner, at its latest version. A runner that is behind updates itself at start.
-
Node, in the runner's tool cache and on the
PATH.actions/setup-nodefinds it and skips its download. -
The package manager, in corepack's cache.
corepack enableneeds no network. - The system libraries a headless browser needs. Installing them with apt took about 20 seconds in every browser job; the step went from 41 seconds to 21.
- The actions themselves. Every job downloads the same few actions from GitHub. The runner has a little-known setting for a local archive directory:
ACTIONS_CACHE=/opt/ci-runner/actions
while read -r REPO SHA; do
DIR="$ACTIONS_CACHE/$(echo "$REPO" | tr / _)"
mkdir -p "$DIR"
curl -fsSL --proto '=https' -o "$DIR/$SHA.tar.gz" "https://github.com/$REPO/archive/$SHA.tar.gz"
done <<'ACTIONS'
actions/checkout <commit sha>
actions/setup-node <commit sha>
actions/upload-artifact <commit sha>
ACTIONS
echo "ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE=$ACTIONS_CACHE" >> /home/runner/actions-runner/.env
A workflow that pins one of those commits gets it from disk. Any other version downloads as usual.
The build also switches off what a fresh Ubuntu does on its own at boot: the apt timers, unattended upgrades, snapd. Each held a lock or burned CPU in the first seconds.
One thing went the other way. On GitHub's runners a dependency cache saves time. On ours a cold install is as fast as a cache restore, and saving the cache afterwards uploads slowly from AWS to GitHub. We removed the cache step.
Where the 28 seconds go
We wanted to know what was left, so the image now reports it. A hook that runs at the start of every job prints the boot milestones into the job log, in seconds since the kernel started:
Boot timings (seconds since kernel boot):
cloud-init local: +5 s
network online: +9 s
cloud-config: +10 s
boot script: +10 s
runner started: +12 s
runner connected: +15 s
job received: +16 s
We read 22 recent jobs and joined them with the launch time the control plane records. Three of them ran on an instance that was already booting for another job, so they have no boot of their own to measure. The other 19 give this:
The sample's median is 27 seconds, one under the week's 28.
Three things surprised us.
Eight seconds pass before EC2 hears about the job. The webhook, an asynchronous hand-off to the worker, a call to GitHub for the runner registration, then RunInstances. It is the largest piece we fully control, and we had never looked at it.
The operating system is the biggest piece: eight seconds from kernel to network. Most of it is cloud-init waiting for the network. Nothing we baked into the image touches it.
The runner itself is quick. Two seconds to start, three to connect, one for GitHub to hand it a job. Six seconds for everything GitHub-specific.
So the image work took the boot from 65 seconds to 28, and none of what remains is downloading. Whole-second timestamps mean each phase can be off by one, and 19 jobs is a small sample. It is enough to say where not to look.
What we refused to pay for
- A warm pool. One idle instance per pool would start the first job of a burst in 2 to 5 seconds. The second job of the same push would still boot its own. The idle hours cost about as much per month as eight thousand of our jobs, for a saving nobody has asked for.
- Fast snapshot restore. A new instance reads its disk lazily from snapshot storage. AWS sells a way to skip that, priced per hour per zone, at a monthly cost many times what the runners themselves cost.
- An image per repository. Baking each repository's dependencies would skip its install step, 5 to 10 seconds of a 45 second job. It would also mean an image, a launch template and a pool per repository, and a bigger image loads more slowly.
- Launching ahead. A job that depends on others could have its machine started early. We designed it and then found that GitHub does not create such a job until the jobs it depends on have finished. There is no job to launch for until it is already waiting.
What the machine is worth
The point of owning the boot was to choose the machine. Same commit, median of two runs:
Our 2 vCPU runner is about as fast as GitHub's. Eight vCPUs make the same suites 3 to 5 times faster, because the work was parallel and had been waiting for cores.
That raised a question we had answered before by habit: do we still need to shard? We measured it. On the same instance type, running a suite as one job instead of three shards used 7 instances instead of 11 and cost less per run, and it ended the pull request 75 seconds later. We kept the shards. A minute of every developer's wait is worth more than a cent and a half.
What it does not do
- It does not start in two seconds. GitHub's hosted runners do. Jobs of a few seconds stayed there.
- It does not shrink the eight seconds of OS boot. A lighter base image is the untried lever.
- The profile is a snapshot. Nineteen jobs on one day, on the newest image. The hook keeps printing, so the next reading is one script away.
What we took from it
- Profile the boot before buying your way around it. Baking the image was worth 37 seconds and cost nothing to run. The next few seconds are priced in idle machines.
- Put the measurement in the product. The timings are in every job log, so nobody has to set up a benchmark to see a regression.
- Measure the habit too. Sharding was the right call on 2 vCPUs and is still the right call on 8, and now we know why.


Top comments (0)