Cloud Run configuration shift for low‑traffic workloads cost reduction
0 reputation · 16 Jun 2024, 21:16 UTC
0 reputation · 16 Jun 2024, 21:16 UTC
Lower the ongoing cost of running a low‑traffic workload on Google Cloud while keeping the service responsive to occasional requests.
The Well‑Architected Framework’s cost‑optimization pillar recommends granular control of performance and cost parameters to maximize business value.
It is unclear which Cloud Run‑specific setting (for example, CPU allocation, concurrency limit, or minimum instances) should be changed first to achieve the greatest cost saving without hurting latency for sporadic traffic.
34775 reputation · 17 Jun 2024, 07:55 UTC
For a service that receives only a handful of requests per day, the first setting to adjust is minimum instances. Setting min‑instances to 0 ensures you aren’t billed for idle instances during the long periods of no traffic.
With min‑instances=0, Cloud Run will spin up a new instance only when a request arrives. This increases cold‑start latency compared to keeping a warm instance, but for sporadic traffic the trade‑off is usually acceptable. You can mitigate the impact by keeping the default CPU allocation mode (“CPU only when request”) and by using a higher concurrency (default 80) to keep fewer instances alive.
min‑instances to 0.always‑on‑CPU setting, switch it back to the default to avoid paying for idle CPU.After setting min‑instances=0, you can further tweak:
min‑instances=0 removes the idle‑instance charge.CPU only when request (default) or CPU always; the former saves cost when idle.min‑instances to 0 in the Cloud Run console or via gcloud run services update SERVICE --min-instances=0.CPU allocation mode is CPU only when request (default).instance count and latency in Cloud Monitoring after the change.concurrency (e.g., to 80) or lowering memory slightly, then re‑monitor.To fine‑tune concurrency and memory, could you confirm whether the workload is more CPU‑bound or memory‑bound during peak requests? This will influence whether you should increase concurrency or reduce memory.
Use comments to ask for clarification. Post a solution as an answer.
5,540 reputation · 17 Jun 2024, 04:38 UTC
Switching the CPU mode to CPU on demand (the default for Cloud Run) ensures you pay only while the request is actively using CPU. For a few requests a day, this can cut idle CPU charges by up to 90 %. The trade‑off is a marginal increase in cold‑start latency because the CPU is provisioned on first use.
Cloud Run’s free tier (180 000 requests and 360 000 GB‑seconds of compute per month) covers most low‑traffic services. Verify your usage in the Cloud Billing console to ensure you stay within these limits before tweaking other settings.
concurrency (e.g., to 80 or 100) reduces the number of instances needed, lowering cost.After setting min‑instances=0, adjust CPU mode and concurrency, then monitor Instance Count and Request Latency in Cloud Monitoring to validate the trade‑offs.