Sub topic 8
Choosing runner types and sizes
This chapter assumes you can read job durations in the Actions UI and tell queue time from execution time (earlier chapters). You should also be comfortable editing runs-on in a workflow file.
What a runner choice changes
The runs-on key decides which machine runs a job. That choice affects two numbers you already know how to measure:
- Execution time depends on CPU count, memory, disk speed and the operating system.
- Queue time depends on whether a matching runner is free when the job is created.
A runner change only helps if one of these numbers is the problem. If a job spends 20 seconds queued and 6 minutes in npm test, a bigger machine may help. If it spends 4 minutes queued, a bigger machine won't help unless the new label has more free capacity.
The main options
| Option | Typical label | Strength | Common drawback |
|---|---|---|---|
| Standard GitHub-hosted | `ubuntu-latest` | No setup, clean machine each job | Fixed, modest CPU and memory |
| Larger GitHub-hosted | A label you define, such as `ubuntu-4core` | More vCPUs and memory, same clean-machine model | Paid per minute, needs a supported plan |
| Windows or macOS hosted | `windows-latest`, `macos-latest` | Required for platform-specific builds | Higher per-minute cost, often slower to start |
| Self-hosted | `[self-hosted, linux, x64]` | Full control over hardware and preinstalled tools | You maintain it, and jobs queue if all runners are busy |
Check GitHub's current documentation for exact CPU counts and prices. Both change, and public and private repositories can get different standard runner sizes.
Measure before you pay
Run the same job on two runner labels and compare. A matrix does this in one workflow run. The ubuntu-4core label below is a placeholder. Replace it with the name of a larger runner you have created in your organization, or the job will wait forever for a runner that doesn't exist.
name: runner-compare
on:
workflow_dispatch:
jobs:
test:
strategy:
fail-fast: false
matrix:
runner: [ubuntu-latest, ubuntu-4core]
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- name: Show hardware
run: |
echo "cpus: $(nproc)" >> "$GITHUB_STEP_SUMMARY"
free -m | sed -n '2p' >> "$GITHUB_STEP_SUMMARY"
- run: npm testThen pull the durations and the runner that served each job. The jobs API reports runner_name and labels next to the timestamps:
gh api repos/{owner}/{repo}/actions/runs/1234567890/jobs \
--jq '.jobs[] | {name, runner: .runner_name, run_seconds: ((.completed_at | fromdateiso8601) - (.started_at | fromdateiso8601))}'Repeat the comparison on several runs. A single run can be skewed by a cold cache or a noisy neighbor.
Will more cores help?
A larger runner only speeds up work that can use the extra resources. Watch the nproc output in the summary and compare it against what the step does.
- Test runners that spawn workers (Jest, pytest-xdist) and compilers with parallel builds often scale with cores.
- A single-threaded step, such as many linters or
npm ciunpacking, gains little. - Network-bound steps, such as downloads, won't speed up with CPU.
- Memory-starved jobs that swap or get killed can improve a lot from more RAM.
Doubling the cores rarely halves the time. If a 4-core runner gives a 30% gain at twice the per-minute price, the job costs more per run.
Decision flow
Gotchas
ubuntu-latestis a moving label. When GitHub changes what it points to, tool versions and timings can shift. Pin a version such asubuntu-24.04when you need stable comparisons.- Windows and macOS jobs are billed at higher rates than Linux. Move jobs that don't need them to Linux.
- Self-hosted runners don't start from a clean machine. Old caches and files can make timings look better than a fresh run would, or leave a runner in a bad state.
- Put a larger runner only on the jobs on your critical path. Speeding up a job that isn't on the critical path doesn't shorten the run.
Exercise
A job takes 9 minutes. The Actions UI shows 40 seconds between the job being created and starting, and npm test accounts for 7 of the 8 minutes 20 seconds of execution. The test command runs in a single process. Should you move this job to a larger runner first? Explain.
Show answer
Probably not. Queue time is small (40 seconds), so runner capacity isn't the problem. The slow step is a single-process test run, so extra cores won't be used. Try sharding or a parallel test runner first, then re-measure. A larger runner becomes worth trying once the tests can use more cores.