Jump to Content
Serverless

Run more workloads on Cloud Run with new CPU allocation controls

September 13, 2021
https://storage.googleapis.com/gweb-cloudblog-publish/images/Cloud_Run.max-2600x2600.jpg
Steren Giannini

Group Product Manager

Try Google Cloud

Start building on Google Cloud with $300 in free credits and 20+ always free products.

Free trial

Cloud Run, Google Cloud's serverless container platform, offers a very granular pay-per-use pricing, charging you only for CPU and memory when your app processes requests or events. By default, Cloud Run does not allocate CPU outside of request processing. For a class of workloads that expect to do background processing, this can be problematic. So today, we are excited to introduce the ability to allocate CPU for Cloud Run container instances even outside of request processing.

https://storage.googleapis.com/gweb-cloudblog-publish/images/cloud_run_container.max-1000x1000.jpg

This feature unlocks many use cases that weren't previously compatible with Cloud Run:

  • Executing background tasks and other asynchronous processing work after returning responses

  • Leveraging monitoring agents like OpenTelemetry that may assume access to CPU in background threads

  • Using Go's Goroutines or Node.js async, Java threads, and Kotlin coroutines

  • Moving Spring Boot apps that use built-in scheduling/background functionality

  • Listening for Firestore changes to keep an in-memory cache up to date

Even if CPU is always allocated, Cloud Run autoscaling is still in effect, and may terminate container instances if they aren't needed to handle incoming traffic. An instance will never stay idle for more than 15 minutes after processing a request (unless it is kept active using min instances).

Combined with Cloud Run minimum instances, you can even keep a certain number of container instances up and running with full access to CPU resources. Together, these functionalities now enable new background processing use cases like using streaming pull with Cloud Pub/Sub or running a serverless Kafka consumer group.

When you opt in to "CPU always allocated", you are billed for the entire lifetime of container instances—from when a container is started to when it is terminated. Cloud Run's pricing is now different when CPU is always allocated: 

  • There are no per-request fees

  • CPU is priced 25% lower and memory 20% lower 

Of course, the Cloud Run free tier still applies, and Committed Use Discounts can give you up to 17% discount for a one-year commitment.

How to allocate always-on CPU

You can change your existing Cloud Run service to always have CPU allocated from the Google Cloud Console:

https://storage.googleapis.com/gweb-cloudblog-publish/images/cpu_allocation_and_pricing.max-700x700.jpg

or from the command line:

gcloud beta run services update SERVICE-NAME --no-cpu-throttling

We hope this change will allow you to run more workloads on Cloud Run successfully while still benefiting from its low-ops characteristics.

To learn more about Cloud Run CPU allocation, check out our documentation and pricing page. To learn more about Cloud Run, check out our getting started guides.

Posted in