Sub topic 11
Balancing throughput, latency, and CI cost
This chapter assumes you can already enable a merge queue, run workflows on the merge_group event, and read the queue settings. You need to be comfortable with GitHub Actions concurrency and billing basics. Here you will learn how the queue settings trade speed against cost, and how to pick values for your team.
The three quantities in tension
Every queue setting moves one of three quantities.
- Throughput is how many pull requests merge per hour.
- Latency is how long one pull request waits between joining the queue and landing on
main. - CI cost is the runner minutes spent on
merge_groupruns, including runs whose results are thrown away.
You cannot improve all three at once. Larger groups cut cost per merged pull request but raise the cost of a failure. More concurrent builds cut latency but burn more speculative runs. The goal is to find the cheapest configuration that keeps latency acceptable at your real pull request volume.
What each setting changes
The queue builds temporary merge group branches, each containing the base branch, the entries ahead of it, and its own changes. Each branch triggers one merge_group run of your required checks. Every setting below changes how many of those runs happen, how many run at once, or how many pull requests each run covers.
| Setting (ruleset name) | Default | Effect on throughput and latency | Effect on cost |
|---|---|---|---|
| Maximum pull requests to build (`max_entries_to_build`) | 5 | More groups are tested in parallel, so a pull request starts testing sooner. | More speculative runs. If an early group fails, later runs built on top of it are wasted. |
| Maximum pull requests to merge (`max_entries_to_merge`) | 5 | Several pull requests land in one merge, so fewer sequential builds are needed. | One run is shared by up to this many pull requests. |
| Minimum pull requests to merge (`min_entries_to_merge`) | 1 | A value above 1 makes early arrivals wait for company. | Fewer, fuller groups. |
| Wait time to meet the minimum (`min_entries_to_merge_wait_minutes`) | 5 | Sets how long the queue holds out for the minimum before merging a smaller group. | Trades latency for fuller groups. |
| Status check timeout (`check_response_timeout_minutes`) | 60 | A short value frees a stuck slot sooner. | A long value lets a hung job hold up the queue and bill minutes. |
| Grouping strategy (`grouping_strategy`) | `ALLGREEN` | Decides whether one failure sinks the whole group. | Changes how much work is redone after a failure. |
The default values above were current when this was written. Check your repository's settings page, because defaults can change.
A worked cost comparison
Suppose a team merges about 40 pull requests per working day. The required checks take 20 minutes of wall-clock time and use 30 runner minutes in total, because several jobs run in parallel. Assume a few failures, but start with a clean day.
- Group size 1, build concurrency 1. Every pull request gets its own run, and runs are strictly serial. That is 40 runs, or 1,200 runner minutes. The queue can merge only 3 pull requests per hour (20 minutes each). A burst of 10 pull requests means the last one waits more than 3 hours.
- Group size 1, build concurrency 5. Runs overlap, so the last of the 10 waits about 40 minutes. Cost is still 1,200 runner minutes, plus waste whenever an early entry fails and later groups must restart.
- Group size 5, build concurrency 3. Full groups of 5 mean about 8 runs, or 240 runner minutes. Throughput is high because each 20-minute run lands 5 pull requests. The price is that a lone pull request may wait up to the wait-time setting for company, and any failure affects 5 pull requests instead of 1.
The numbers are illustrative, but the pattern holds. Group size mostly controls cost. Build concurrency mostly controls latency during bursts. Neither helps if your CI is slow, so shortening the required checks is often the largest saving.
Concurrency and speculative waste
Build concurrency lets the queue test group 2 before group 1 has finished. Group 2's branch already includes group 1's changes. If group 1 passes, group 2's result is valid immediately. If group 1 fails, group 2's run no longer matches what will merge, so it is discarded and rebuilt without the failed entry.
Waste therefore grows with two factors: how often groups fail, and how many groups are in flight behind them. A team with a flaky test suite should keep concurrency low, because each flake restarts everything behind it. A team with stable CI can raise concurrency without much penalty.
A rough rule: set build concurrency to the number of groups that finish during one CI duration under your typical load, and stop there. Beyond that, extra slots stay idle or only add speculative runs.
Group size and the failure blast radius
Larger groups cut cost but make failure more expensive. The effect depends on the grouping strategy.
ALLGREENrequires every entry in the group to pass the required checks. A failing entry causes a failed group, the offending pull request is removed, and the remaining entries are rebuilt without it. This is the safest choice, and it costs the most when failures are frequent.HEADGREENonly requires the checks on the head of the group to pass. It spends less on retries but gives weaker guarantees about each intermediate state, so use it only if your checks always test the cumulative result and you accept that tradeoff.
If about 1 in 10 pull requests fails in the queue, a group of 5 fails roughly 40% of the time (1 − 0.9⁵ ≈ 0.41). Each failure forces a rebuild, so large groups can cost more than they save when the failure rate is high. Failures at queue time are usually flakes or semantic conflicts. If you see many of them, fix the flakes before you tune group size.
Latency and the wait time
The minimum group size and its wait time exist to improve cost, but they add a floor to latency. With a minimum of 3 and a wait of 5 minutes, a single pull request in a quiet period sits for up to 5 minutes before its run even starts. For a team that mostly works in business hours with steady traffic, this delay is small. For a team with sparse traffic, set the minimum to 1 and let grouping happen naturally when pull requests arrive together.
Reducing the cost of each run
Settings only decide how many runs happen. You can also make each run cheaper.
- Keep the required check list short. Every required check runs in every
merge_grouprun. - Stop superseded runs on pull requests, but never cancel runs on the queue branches. A cancelled run reports a failure and ejects the group.
name: CI
on:
pull_request:
branches: [main]
merge_group:
types: [checks_requested]
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Run tests
run: make testThe concurrency group uses github.ref, which is unique for each temporary gh-readonly-queue branch, so queue runs never cancel each other. The timeout-minutes value is shorter than the queue's check timeout, so a hung job fails fast and frees its slot.
A tuned ruleset for a busy team
This ruleset body fits a team with stable CI that merges many pull requests in bursts. It allows more concurrent builds, keeps groups small enough to limit failure impact, and uses a short wait.
{
"name": "main-merge-queue",
"target": "branch",
"enforcement": "active",
"conditions": {
"ref_name": {
"include": ["refs/heads/main"],
"exclude": []
}
},
"rules": [
{
"type": "merge_queue",
"parameters": {
"merge_method": "SQUASH",
"grouping_strategy": "ALLGREEN",
"min_entries_to_merge": 1,
"max_entries_to_merge": 4,
"min_entries_to_merge_wait_minutes": 2,
"max_entries_to_build": 6,
"check_response_timeout_minutes": 40
}
}
]
}The values are a starting point. Change one setting at a time and compare queue wait time and runner minutes over a week before changing the next.
Edge cases
- Timeout too low. A
check_response_timeout_minutesshorter than your slowest normal run removes healthy pull requests. Set it comfortably above your 95th percentile run time. - Required check that never reports. If a required workflow does not trigger on
merge_group, the group waits for the full timeout and then fails. That wastes the slot for the whole timeout period. - Mixed run lengths. A group finishes only when its slowest required check finishes. One slow job sets the pace for every group, so splitting or speeding it up helps more than any queue setting.
Exercise
A team merges about 30 pull requests a day with 25-minute CI and a 15% failure rate in the queue. Developers complain that merges are slow during morning bursts, but the CI bill is also growing. They are considering raising both maximum group size to 10 and build concurrency to 10. What would you advise?
Show answer
Advise against raising both. With a 15% failure rate, a group of 10 fails most of the time (1 − 0.85¹⁰ ≈ 80%), so most runs would be discarded and rebuilt, and the bill would grow. Ten concurrent builds would add speculative runs that fail whenever an earlier group fails. Instead, address the failure rate first by fixing flaky tests. Then raise build concurrency moderately (for example 3 to 5) to cut burst latency, and use a modest group size (for example 3 to 4) to reduce cost per pull request. Measure wait time and runner minutes for a week after each change.