My project uses a lot of runners. It has many workflows, and the CI part runs even on every branch. In the first month of the project my GitHub Actions minutes were already used up halfway through the month, which is why I moved to self-hosted runners: my laptop first, and then ephemeral runners in an Azure Container Apps job, one container per job, scaled from zero by KEDA. I set them up at 2 vCPU and 4 GiB because that was the largest size a job gets and I did not know what the jobs needed. Moving the cost to Azure only moved the problem. In the first week the budget went so fast that I had to stop the runner: it had cost €8.75 in the six days from October 23 to 28. When I switched it back on in the week of November 18, it cost €7.14 in four days, between €1.09 and €2.81 a day. This was still too high, so I went looking for what to cut.
The cost of a runner can be cut in three ways:
- Reduce the time: less time that a container is running without doing anything, such as the idle timeout.
- Reduce the jobs: fewer runs, so the runner is busy for fewer hours.
- Reduce the resources: a smaller container, so every second of running is cheaper.
The first two do not make a job itself run longer. The third has a disadvantage: a container with fewer resources can take longer to do the same job, so part of what you save per second you can lose again in seconds.
This post is the list of what I did, in the order I did it, one section per way. I changed several things in quick succession, so I only compare numbers lightly at the end.
1. Reduce the time: shorten the idle timeout
KEDA starts a runner for every queued job it sees, but my laptop runner may take the job first. The container then has no job and waits, billed, until its idle timeout ends.
I first set that timeout to 5 minutes, on purpose. A workflow often queues its jobs one after the other, because of needs:. A runner that waits 5 minutes is still there when the next job is queued, so that job starts at once. A runner that has already gone costs a new start, which takes 30 to 60 seconds: the scaler's check, the container start and the registration. So 5 minutes bought speed, and I paid for it in idle runners.
Now I have set it to 90 seconds. GitHub hands a queued job to an idle runner within seconds, so a runner that has had no job for 90 seconds is almost always surplus. The price is that some jobs, the ones queued more than 90 seconds after the previous one, will find no runner and wait for a cold start. That is more waiting time. It matters less to me than the cost: a minute more before a check is green is fine, a bill that empties my budget is not.
2. Reduce the jobs: stop running workflows that have nothing to do
My strategy here is not a one-off clean-up. Every now and then I look at my workflows and at which change triggers which one. When I have the feeling that too many are running, I show Claude which workflows ran for a change and ask whether that is correct.
Before this, every deploy workflow started on any push to main, whatever had changed. Between October 14 and November 21 each one got a trigger that only fires for the files it bundles: a paths: list with the Worker's own folder and the shared code it bundles, with the tests excluded. A test fails if a file a Worker bundles is missing from its list, so the lists don't go stale. The CI workflow, which runs on every branch, got its filters last, on November 21. The browser and editor checks were jobs inside ci.yml, and paths: applies per workflow, so I first had to split them into their own workflows to give them their own lists. Where a path filter can't express it, the job decides for itself: the photo upload in the site sync only runs when the push contains uploads/, and the smoke test skips itself when another deploy of the same commit is still running.
Two other savings did not need a filter at all:
- The push guard is a step, not a job. It used to be its own job, and a separate job costs an extra runner start on every run. Now it runs as a step inside each guarded job.
- Cancelling runs that are started again or no longer needed. A
concurrencyrule withcancel-in-progresscancels an older run when a newer push arrives, so the old one doesn't keep a runner busy.
I did not count runs before and after, so I can't say how many runs this saved. The editor CI is also split into three parallel jobs, but that was to make it faster, not cheaper.
3. Reduce the resources: look at what the runner uses, then take it down
The last step was the container itself. I looked at the job's own metrics page, over seven days:
- Memory: the peak stayed under 1.4 GiB. At 4 GiB that is a third of what I was paying for.
- CPU: the average stayed under 1 core, but the Max view per half hour reached 1.8 to 2.0 cores on most days. The average includes the idle hours, and the Max says what a job wants while it runs.
Memory is the number to leave headroom on, because a container that goes over its limit is killed. CPU is different: a container that wants more cores than it has does not die, it gets slower. So memory sets the floor and CPU is the part to watch, because that is where the disadvantage of this way sits: less CPU can mean a longer running time.
Pick a smaller size, and know the pairs
The job's resource blade shows two separate boxes for CPU and memory, which suggests you can set them independently. You can't. Saving a value that is not one of the fixed pairs fails with a message that lists them:
0.25 / 0.5Gi, 0.5 / 1.0Gi, 0.75 / 1.5Gi, 1.0 / 2.0Gi, 1.25 / 2.5Gi, 1.5 / 3.0Gi, 1.75 / 3.5Gi, 2.0 / 4.0Gi
Memory is always twice the CPU in GiB. With a 1.4 GiB peak, 1.0 / 2.0Gi is the smallest pair that is safe: the next one down leaves about 0.1 GiB above the peak. I went from 2.0 / 4Gi to 1.5 / 3Gi first, then to 1.0 / 2Gi, and put the final size in the Bicep defaults, so a rerun of the deploy workflow doesn't put the old size back.
The pairs move together, but they are not priced alike. On a day with €2.81 of runner cost, the vCPU meters were about 80% of the compute bill. CPU is where the money is, and also where the risk of longer jobs is.
What I left alone: four runners at the same time
The job also has a cap on how many runners may run at the same time. I left it at 4.
I have a lot of workflows that run every time. Besides the four runners in Azure, my laptop runner and the deployment slot can take jobs too, so up to six can run at the same time. The deployment slot is a runner with the deploy label: the workflow that deploys the website only runs there, and I set that label up on my laptop and on the ACA runner. I did that for speed, not for cost. That workflow mostly ended up last in the queue, and then I had to wait longer before I could test the site. I thought that lowering the cap would not save anything, because the same jobs would still have to run, only later. The cost of a job is its runner seconds, and those are the same whether four run side by side or two run one after the other. A lower cap would only make me wait longer for the checks.
There is one thing a cap does change. KEDA starts a runner for every queued job, up to the cap, and when the laptop takes a job first, that runner idles until the idle timeout ends. A higher cap means more idle runners at once. With the idle timeout at 90 seconds that waste is small, so I looked at the timeout first and left the cap alone. I did not try other values, so I can't say what a lower or higher cap would cost.
What the numbers say, lightly
- Cost per busy hour is the cleanest comparison, because it doesn't depend on how many jobs ran. The Avg view of the job's execution metric is 0 or 1 (something is running, or nothing is), so it gives busy hours. November 19 to 21, at the old size, cost about €0.165 per busy hour. On November 23, at the new size, it was €0.072. That is what half the price per second looks like.
- The daily bill fell from about €1.80 on average for November 19 to 21 to €0.61 on November 23. The idle timeout and the path filters came before the size change, so they were already in place for some or all of those days. I did not write down the dates, so I can't tell how much of that drop is the size and how much is fewer busy hours.
- Job times: according to GitHub's Actions performance metrics, the average job run time over all jobs was 2m10s in the week before and 2m11s after, and the failure rate was 3% in both. I expect the CPU-heavy jobs to take a bit longer, because the Max CPU now sits at the 1 core limit in many busy half hours. I did not measure that run by run.
What I can't say
I changed the idle timeout, the path filters, the workflow structure and the size one after the other, without writing down dates or job durations, and the runner was switched off for part of the comparison. So I can't say which step saved how much. The cost per busy hour belongs to the size, since it is a rate. Everything else is a mix.