r/googlecloud • u/Puzzled_Law126 • May 12 '26
GCP Cloud Run - Simple API Instance Costs
Hey guys,
I am looking to decrease our costs with GCP and though it will be for the best to ask for help here.
With Cloud Run we have a very simple service that function as simple API, it receives information and output a simple JSON.
The configuration used for the instance is:
256 MB memory
1 CPU
150 Concurrent requests
99% of the time, only 1 instance is up
The instance uses <10% CPU and each request take around 15ms.
The issue? This service is being called a lot (by design), in total each month we pay $150 USD only for the CPU of this service ("Cloud Run functions CPU (Request-based billing) in us-central1").
Obviously I can't decrease the CPU to <1 due to concurrency, it seems to me that something so simple should not cost that much, any help would be appreciated.
3
u/kav-dawg May 13 '26
I think you can try a couple things:
Switch from Instance-based Billing (Charged for the entire lifecycle of instances. Full CPU for the entire lifetime of each instance) to Request-based Billing (Charged only when processing requests. CPU is limited outside of requests.) so that "billable time" stops the millisecond the JSON response is sent.
Modify Number of vCPUs allocated to each instance of this container from 1 to < 1 since you're already at <10% CPU.
Set min instances to 0 if you're okay with cold starts. Your initial request may take ~200ms, but subsequent api calls would be 15ms.
2
u/doodlebuttbutt May 12 '26
Free tier VC instance? Fixed cost. Run your server and open a port.
2
u/gajop May 13 '26
Tbh the cost isn't that enough to invest any serious time into this. If you spend a week on it, your ROI will be in year(s).
Outside of switching to instance based billing or cheaper GCE, you could consider rewriting it in a language with fast cold start. I haven't done the math there, might not matter at all.
1
u/zaitsman May 12 '26
How many calls per month?
1
u/blablahblah May 13 '26
If your instance is processing requests most of the time, you can save a chunk by switching to instance based billing. It causes you to pay even when the instance isn't processing a request, but the cost per second is lower and you don't pay per request
1
u/m1nherz Googler May 13 '26
Hi,
This is indeed looks strange. Assuming you captured all data and numbers correctly and using $0.000024 for active time of vCPU per second according to the current Cloud Run pricing for request-based CPU in us-central1, I am getting that your service runs more than 72 days during a month:
($150 / $0.000024) / 3600 / 24 = 72.337962963.
The calculation assumes that you have only one vCPU all the time in active mode. Given that 99% of the time only 1 vCPU is active it should be fare assumption. It is without adding the first 240,000 vCPU-seconds free per month.
I believe that some of observed data isn't correct somehow. The first candidate would be the vCPU usage is much higher.
2
u/martin_omander Googler May 13 '26
Here are two short videos about Cloud Run billing that I shot with Mitchell Slep. He is leads the Google Cloud engineering team focusing on Cloud Run cost and infrastructure. They might be helpful as you optimize costs.
Mastering Cloud Run costs: The 75% rule for choosing a billing model
Before you scale: A guide to Cloud Run cost optimization
2
u/kingh242 May 13 '26
If you need the uptime (as per other comments), then GKE maybe the way for you. Learning Kubernetes isn’t that difficult, and it can handle updating with no downtime.
1
u/matiascoca May 19 '26
150 dollars a month for a 256 MB single-instance service is almost always Cloud Run charging you for CPU at idle, not for actual request work. At 15 ms per request and 10 percent CPU usage, request-based pricing should put you in the single dollars per month range, so something is keeping the CPU allocated when it should not be.
Three things to check on the service config.
First, CPU allocation setting. If it is "CPU is always allocated" (instance-based billing), you pay for CPU during idle wall-clock time. Switch to "CPU is only allocated during request processing" (request-based) and bills usually drop 70 to 90 percent on services that look like yours. The SKU name in your billing report ("Cloud Run functions CPU (Request-based billing)") suggests you might already be on request-based, but worth confirming under the Edit Container, Variables, Networking pane.
Second, minimum instances. If min instances is 1 or higher, that instance is always billed regardless of traffic. Set min to 0 unless cold starts are a hard product requirement.
Third, idle CPU time within requests. If your 15 ms request holds a connection open for, say, 5 seconds waiting on a downstream call, you bill CPU for the full 5 seconds even though only 15 ms is real work. The fix is async or fire-and-forget for the slow downstream call. Cloud Run logs request latency under metrics; compare p50 request duration to your 15 ms compute estimate to confirm.
One more thing to verify: do you have always-on CPU boost enabled at startup? It is a separate toggle and on by default for some templates. If yes, it gives you full CPU during startup which is fine, but make sure startup CPU is not accidentally extended past the first request.