---
title: "Match test concurrency to the runner"
description: "Measure worker counts against available CPU and memory. More workers help only while the runner has capacity."
url: https://starsling.dev/ci-playbooks/techniques/tune-test-workers
canonicalUrl: https://starsling.dev/ci-playbooks/techniques/tune-test-workers
---

# Match test concurrency to the runner

Measure worker counts against available CPU and memory. More workers help only while the runner has capacity.

## How to choose an approach

Compare the examples by repository setup, prerequisites, and risks before adopting one. Each company implemented this in its own environment; measure each change against your own baseline.

- **[Anthropic](https://starsling.dev/ci-playbooks/anthropic#tune-worker-width)**: Use it when A fixed worker count has never been measured, or workers contend for memory, physical cores or a shared host. Check before adopting: Nested worker processes and other virtual machines on the same host count toward the width.
- **[Mastra](https://starsling.dev/ci-playbooks/mastra#test-workers)**: Use it when Parallel tests and build output compete for limited runner memory. Check before adopting: Preserve the separate build heap requirement and measure peak memory, elapsed time and failures across worker counts.
- **[OpenAI](https://starsling.dev/ci-playbooks/openai#measured-concurrency)**: Use it when Test parallelism is a default or a guess for this runner. Check before adopting: More parallel workers can increase memory pressure and contention. Compare the same workload and runner, including reliability and total minutes.
- **[Stripe](https://starsling.dev/ci-playbooks/stripe#measure-worker-count)**: Use it when Tests run serially, or worker counts and runner sizes were chosen without measurement. Check before adopting: Isolate shared accounts and ports before adding workers, and keep tests that verify serial behavior in a serial lane. Measure each change separately; the source PRs changed workers and machines together.

## Apply this technique

````text
Evaluate and apply this CI technique to my repository: Match test concurrency to the runner.

Measure worker counts against available CPU and memory. More workers help only while the runner has capacity.

Read the technique and its source-backed company examples: https://starsling.dev/ci-playbooks/techniques/tune-test-workers.md

Inspect this repository’s CI workflows, build and test commands, dependencies, and recent run timings. Identify where this technique applies and explain the expected benefit using this repository’s evidence.
Measure a baseline from recent comparable runs: elapsed time, queue time, runner minutes and failures where available. If data is unavailable, say what cannot be measured.
Compare relevant company approaches, checking prerequisites, platform differences and tradeoffs. Rank applicable options by evidence, fit and measurable opportunity; do not present company results as predictions for this repo.
Recommend the smallest safe change, show what checks and fallback paths remain, and ASK ME WHICH CHANGE TO APPROVE BEFORE EDITING ANY FILES.
Only after approval, work on a new feature branch, make one reversible change, and open a reviewable pull request. Never merge or push to a default or protected branch.
Keep required checks, test coverage, deployment and release behavior intact. Validate the change and compare equivalent runs where possible; report limitations and what should be monitored after merge.
````

## How companies used this technique

Read what each company changed and follow the original sources.

### Anthropic: Set test worker width from the actual host

Bun removed the CPU and thread caps that held its Linux test agents to two usable cores, and sized the parallel test width from the available cores. A follow-up capped the width at four on macOS, where each M2 Ultra host runs two tart virtual machines and every coordinator forks its own workers.

Evidence: Source PR/commit evidence

Use it when: A fixed worker count has never been measured, or workers contend for memory, physical cores or a shared host.

Before applying it: Nested worker processes and other virtual machines on the same host count toward the width.

[Read more in the Anthropic playbook](https://starsling.dev/ci-playbooks/anthropic#tune-worker-width)

[Primary source](https://github.com/oven-sh/bun/pull/36175)

### Mastra: Fit test concurrency to the runner’s memory

The memory integration configuration capped Vitest threads at two after the source reported runner disconnects and memory pressure.

Evidence: Source PR/commit evidence

The source reports 61 failures in 771 runs. ([Source](https://github.com/mastra-ai/mastra/pull/13937))

The current Vitest configuration expresses the limit as maxWorkers: 2. ([Source](https://github.com/mastra-ai/mastra/blob/f92e947a448a47515acf14df1eddc5fd5c36f424/packages/memory/integration-tests/vitest.config.ts))

Use it when: Parallel tests and build output compete for limited runner memory.

Before applying it: Preserve the separate build heap requirement and measure peak memory, elapsed time and failures across worker counts.

[Read more in the Mastra playbook](https://starsling.dev/ci-playbooks/mastra#test-workers)

[Primary source](https://github.com/mastra-ai/mastra/pull/13937)

### OpenAI: Measure how many tests to run at once

Codex compared Windows Bazel shards at 4, 8 and 12 local test jobs in a forced-test-execution experiment, then set the CI default to 8 with one .bazelrc line. Sharding spreads work across runners; this tunes how much runs at once on each runner.

Evidence: Source PR/commit evidence

Slowest shard: 835.5s to 609.3s at 8 local test jobs, in the experiment the PR cites ([Source](https://github.com/openai/codex/pull/31352))

Use it when: Test parallelism is a default or a guess for this runner.

Before applying it: More parallel workers can increase memory pressure and contention. Compare the same workload and runner, including reliability and total minutes.

[Read more in the OpenAI playbook](https://starsling.dev/ci-playbooks/openai#measured-concurrency)

[Primary source](https://github.com/openai/codex/pull/31352)

### Stripe: Measure workers against the runner

Stripe iOS tried six simulator workers and kept four, which was faster and more reliable, and split Crypto UI tests into separate classes so Xcode could run them in parallel. Stripe Android sized individual device-heavy lanes and raised its managed-device ceiling to match its six shards. Metronome, a Stripe company, moved a publishing job whose doc build was timing out to an 8-core runner, on a suggestion from the Stainless team.

Evidence: Source PR/commit evidence

In the same combined runs, the Crypto UI test step went from about 10 to about 6 minutes. ([Source](https://github.com/stripe/stripe-ios/pull/7333))

Use it when: Tests run serially, or worker counts and runner sizes were chosen without measurement.

Before applying it: Isolate shared accounts and ports before adding workers, and keep tests that verify serial behavior in a serial lane. Measure each change separately; the source PRs changed workers and machines together.

[Read more in the Stripe playbook](https://starsling.dev/ci-playbooks/stripe#measure-worker-count)

[Primary source](https://github.com/stripe/stripe-ios/pull/7333)

## CI optimization is continuous work.

Apply this technique yourself, or use StarSling Runners for faster GitHub Actions and optional agent-driven optimization PRs, which teams on eligible paid plans can turn on.

[Get self-improving CI](https://starsling.dev/products/runners)

## Related techniques

### [Build the test database once for all workers](https://starsling.dev/ci-playbooks/techniques/coordinate-test-setup)

Have one parallel worker apply the schema while the others wait for it, so more workers stop repeating the same setup.

1 implementation · 1 company (Ramp)

### [Isolate state before running tests in parallel](https://starsling.dev/ci-playbooks/techniques/isolated-parallel-tests)

Give concurrent tests independent databases, services, or fixtures so they can share runner capacity without interfering with each other.

5 implementations · 5 companies (DoorDash, Ramp, Shopify, Stripe, Uber)

### [Move unit tests to a parallel-by-default framework, gated on ten clean runs](https://starsling.dev/ci-playbooks/techniques/parallel-test-framework)

Migrate serial tests to a framework that runs them in parallel, and ship each package after ten green runs.

1 implementation · 1 company (DoorDash)

## Company Playbooks

### [Anthropic](https://starsling.dev/ci-playbooks/anthropic)

Run only affected tests

### [DoorDash](https://starsling.dev/ci-playbooks/doordash)

Run build and test in parallel, sharded across CI agents

### [Linear](https://starsling.dev/ci-playbooks/linear)

Benchmark the same job on faster hardware

### [Mastra](https://starsling.dev/ci-playbooks/mastra)

StarSling runners for the slowest test workflow

### [OpenAI](https://starsling.dev/ci-playbooks/openai)

Rank CI fixes by the minutes they save

### [Ramp](https://starsling.dev/ci-playbooks/ramp)

Move a CPU-bound test suite to a faster CPU

### [Shopify](https://starsling.dev/ci-playbooks/shopify)

Let an agent iterate against one CI metric

### [Spotify](https://starsling.dev/ci-playbooks/spotify)

Build arm64 on native arm64 runners

### [Stripe](https://starsling.dev/ci-playbooks/stripe)

Run only the tests a change can reach

### [Uber](https://starsling.dev/ci-playbooks/uber)

Build the merge-queue speculations most likely to be needed

## Related guides

Implementation guides for this technique.

### [Shard tests across parallel jobs](https://starsling.dev/best-practices/github-actions/shard-tests)

Split a long suite with a matrix and your test framework’s sharding support.

### [Cut repeated test setup](https://starsling.dev/best-practices/github-actions/cut-repeated-test-setup)

Move shared fixture work out of individual test cases and keep necessary cleanup.

### [Diagnose slow tests in CI](https://starsling.dev/github-actions/problems/slow-tests)

Check common causes in order and confirm each with workflow evidence.

### [Optimize Playwright tests](https://starsling.dev/github-actions/optimizations/optimize-playwright)

Choose trace and video retention and install the browsers your suite uses.

### [Make Vitest run mode explicit](https://starsling.dev/github-actions/optimizations/optimize-vitest)

Pin run mode to the test command and bound the job with a timeout.

### [Parallelize independent jobs](https://starsling.dev/github-actions/optimizations/parallelize-independent-jobs)

Run independent validation lanes concurrently and keep genuine job dependencies.
