Sub topic 11
Balancing throughput, latency, and CI cost
This chapter assumes you can enable a merge queue, run workflows on merge_group, and read the queue settings. Here you tune those settings. Every setting trades one of three things against the others: how many pull requests merge per hour (throughput), how long one pull request waits (latency), and how many CI minutes you spend (cost).
The three forces
- Throughput is the number of pull requests that reach
mainper hour. - Latency is the time from joining the queue to merging.
- Cost is the CI minutes consumed. Every merge group runs your required checks again.
You cannot minimize all three. Batching pull requests lowers cost and raises throughput, but it can raise latency and widen the blast radius of a failure.
Settings and what they move
| Setting | Ruleset field | Raises | Costs |
|---|---|---|---|
| Build concurrency | `max_entries_to_build` | Throughput | More parallel CI runs, and more wasted runs if an earlier entry fails |
| Maximum group size | `max_entries_to_merge` | Throughput, lower cost per pull request | Larger groups to investigate when a check fails |
| Minimum group size | `min_entries_to_merge` | Lower cost per pull request | Pull requests wait for company |
| Minimum wait time | `min_entries_to_merge_wait_minutes` | Fuller groups | Latency for light traffic |
| Check timeout | `check_response_timeout_minutes` | Fewer false removals for slow suites | A hung check blocks the line longer |
Two example profiles
Consider a team that merges about 40 pull requests a day with a 15-minute test suite.
- Latency first. Set the group size to 1 and build concurrency to 5. Each pull request gets its own check run, so a failure affects only that pull request. A pull request waits roughly one suite duration plus any wait in line. CI cost is one run per pull request, plus runs wasted when an earlier entry fails.
- Cost first. Set the maximum group size to 5 and the minimum wait to a few minutes. Five pull requests share one run, so cost drops by up to about 80 percent. The price is that pull requests wait for the group to fill, and one bad change forces the queue to rebuild the rest.
A cost-oriented ruleset body looks like this:
{
"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": 2,
"max_entries_to_merge": 5,
"min_entries_to_merge_wait_minutes": 5,
"max_entries_to_build": 3,
"check_response_timeout_minutes": 30
}
}
]
}A tuning procedure
- Measure first: median queue time, the share of queue entries that fail, and CI minutes per merged pull request.
- If the failure rate is high, keep groups small. Large groups make each failure expensive, because the queue rebuilds the groups behind the failed one.
- If the failure rate is low and queue time is long, raise
max_entries_to_merge. - If runners sit idle while pull requests wait, raise
max_entries_to_build. - Set the timeout to a little above your slowest normal run. Too short a timeout removes healthy pull requests. Too long a timeout lets a hung check stall everyone.
Exercise
Your suite takes 20 minutes, about 1 in 20 queue entries fails, and pull requests wait about an hour to merge. CI budget is tight. Which two settings would you change first, and in which direction?
Show answer
Raise the maximum group size (max_entries_to_merge) so several pull requests share one 20-minute run, which cuts cost per pull request and queue time. Raise build concurrency (max_entries_to_build) modestly so groups are tested in parallel. The failure rate is low, so large groups are affordable. Keep concurrency moderate to avoid wasted runs when a group fails.