Configure CPU limits for services

This page describes how to specify the number of CPUs to use for each Cloud Run instance. By default, Cloud Run container instances are limited to 1 CPU. You can increase or decrease this value as described in this page.

This page also describes how to enable or disable startup CPU boost , a feature that temporarily increases CPU allocation during instance startup in order to reduce startup latency.

Set and update CPU limits

By default, each instance is limited to 1 CPU. You can change this to any of the values shown in the following table.

CPU and memory table

The following are minimum memory requirements for CPUs:

CPUs Minimum memory
1 128 MiB
2 128 MiB
4 2 GiB
6 4 GiB
8 4 GiB

Alternatively, if you want to use less than 1 CPU, you can select any value between 0.08 and 1, in increments of 0.001. Values greater than 1 must be integer values. If you use less than 1 CPU , the following requirements are enforced:

Setting Requirement
Memory A minimum of 0.5 CPU is needed to set a memory limit greater than 512MiB.
A minimum of 1 CPU is needed to set a memory limit greater than 1GiB.
Concurrency Maximum concurrency must be set to 1 .
Billing The billing settings must be set to request-based billing.
Execution environment You must use the first generation execution environment .

Required roles

To get the permissions that you need to configure and deploy Cloud Run services, ask your administrator to grant you the following IAM roles:

If you are deploying a service or function from source code, you must also have additional roles granted to you on your project and Cloud Build service account.

For a list of IAM roles and permissions that are associated with Cloud Run, see Cloud Run IAM roles and Cloud Run IAM permissions . If your Cloud Run service interfaces with Google Cloud APIs, such as Cloud Client Libraries, see the service identity configuration guide . For more information about granting roles, see deployment permissions and manage access .

Configure CPU limits

Any configuration change leads to the creation of a new revision. Subsequent revisions will also automatically get this configuration setting unless you make explicit updates to change it.

You can set CPU limits using the Google Cloud console, the gcloud command line, or a YAML file when you create a new service or deploy a new revision :

Console

  1. In the Google Cloud console, go to Cloud Run:

    Go to Cloud Run

  2. Select Servicesfrom the menu, and click Deploy containerto configure a new service. If you are configuring an existing service, click the service, then click Edit and deploy new revision.

  3. If you are configuring a new service, fill out the initial service settings page, then click Container(s), Volumes, Networking, Securityto expand the service configuration page.

  4. Click the Containertab.

    image

    • Select the desired CPU limit from the dropdown list, using Customif you want to use less than 1 CPU. Select a value of 1 , 2 , 4 , 6 , or 8 CPUs, or for less than 1 CPU, specify a value from 0.08 to less than 1.00, in increments of 0.01. (See the table under Setting and updating CPU limits for required settings.)
  5. Click Createor Deploy.

gcloud

You can update the CPU limits for a given service by using the following command:

gcloud  
run  
services  
update  
 SERVICE 
  
--cpu  
 CPU 

Replace the following:

  • SERVICE : the name of your service.
  • CPU : the desired CPU limit. Specify the value 1 , 2 , 4 , 6 , or 8 CPUs, or for less than 1 CPU, specify a value from 0.08 to less than 1.00, in increments of 0.01. (See the table under Setting and updating CPU limits for required settings.).

You can also set CPU during deployment using the command:

gcloud  
run  
deploy  
--image  
 IMAGE_URL 
  
--cpu  
 CPU 

Replace the following:

  • IMAGE_URL : a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/hello:latest . If you use Artifact Registry, the repository REPO_NAME must already be created. The URL follows the format of LOCATION -docker.pkg.dev/ PROJECT_ID / REPO_NAME / PATH : TAG .
  • CPU : the value 1 , 2 , 4 , 6 , or 8 CPUs, or for less than 1 CPU, specify a value from 0.08 to less than 1.00, in increments of 0.01. (See the table under Setting and updating CPU limits for required settings.)

YAML

  1. If you are creating a new service, skip this step. If you are updating an existing service, download its YAML configuration :

    gcloud  
    run  
    services  
    describe  
     SERVICE 
      
    --format  
     export 
      
    >  
    service.yaml
  2. Update the cpu attribute:

     apiVersion 
     : 
      
     serving.knative.dev/v1 
     kind 
     : 
      
     Service 
     metadata 
     : 
      
     name 
     : 
      
      SERVICE 
     
     spec 
     : 
      
     template 
     : 
      
     metadata 
     : 
      
     name 
     : 
      
      REVISION 
     
      
     spec 
     : 
      
     containers 
     : 
      
     - 
      
     image 
     : 
      
      IMAGE 
     
      
     resources 
     : 
      
     limits 
     : 
      
     cpu 
     : 
      
      CPU 
     
    

    Replace the following:

    • SERVICE : the name of your Cloud Run service.
    • IMAGE_URL : a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/hello:latest . If you use Artifact Registry, the repository REPO_NAME must already be created. The URL follows the format of LOCATION -docker.pkg.dev/ PROJECT_ID / REPO_NAME / PATH : TAG .
    • CPU : the desired CPU limit value. Specify the value 1 , 2 , 4 , 6 , or 8 CPUs, or for less than 1 CPU, specify a value from 0.08 to less than 1.00, in increments of 0.01. (See the table under Setting and updating CPU limits for required settings.)
    • REVISION with a new revision name or delete it (if present). If you supply a new revision name, it must meet the following criteria:
      • Starts with SERVICE -
      • Contains only lowercase letters, numbers and -
      • Does not end with a -
      • Does not exceed 63 characters
  3. Create or update the service using the following command:

    gcloud  
    run  
    services  
    replace  
    service.yaml

Terraform

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands .

Add the following to a google_cloud_run_v2_service resource in your Terraform configuration:
  resource 
  
 "google_cloud_run_v2_service" 
  
 "default" 
  
 { 
  
 name 
  
 = 
  
 "cloudrun-service-cpu" 
  
 location 
  
 = 
  
 "us-central1" 
  
 deletion_protection 
  
 = 
  
 false 
 # set to "true" in production 
  
 template 
  
 { 
  
 containers 
  
 { 
  
 image 
  
 = 
  
 "us-docker.pkg.dev/cloudrun/container/hello" 
   
 resources 
  
 { 
   
 limits 
  
 = 
  
 { 
 # CPU usage limit 
  
 cpu 
  
 = 
  
 "1" 
  
 } 
  
 } 
  
 } 
  
 } 
 } 
 

The preceding google_cloud_run_v2_service resource specifies a CPU limit under template.containers.resources.limits .

Replace 1 with your desired CPU count. Tip: 1 corresponds to 1 vCPU.

Set startup CPU boost

The startup CPU boost feature for revisions provides additional CPU during instance startup time and for 10 seconds after the instance has started.

The actual CPU boost varies depending on your CPU limit settings:

CPU limit Boosted CPU
0-1 2
2 4
4 8
6 8
8 8

You are charged for the allocated boosted CPU for the duration of the container startup time. For example, if your container startup time is 15 seconds, and you allocate 2 CPU, with startup CPU boost, you'll be charged for 4 CPU during the (possibly shorter) instance startup time, including the 10 seconds after your container finished starting, and for 2 CPU during the rest of the container lifecycle.

If your Cloud Run deployment uses sidecars, and you enable startup CPU boost, all containers receive the CPU boost. Cloud Run determines the boosted CPU amount for each container by the CPU limit.

You can enable or disable startup CPU boost using Google Cloud console, Google Cloud CLI, a YAML file, or a Terraform file.

Console

  1. In the Google Cloud console, go to Cloud Run:

    Go to Cloud Run

  2. Select Servicesfrom the menu, and click Deploy containerto configure a new service. If you are configuring an existing service, click the service, then click Edit and deploy new revision.

  3. If you are configuring a new service, fill out the initial service settings page, then click Container(s), Volumes, Networking, Securityto expand the service configuration page.

  4. Click the Containertab.

    image

    • To enable startup CPU boost select the check box Startup CPU boost . To disable this feature, deselect the checkbox.
  5. Click Createor Deploy.

gcloud

  1. You can enable startup CPU boost for a given service by using the following command:

    gcloud  
    run  
    services  
    update  
     SERVICE 
      
    --cpu-boost

    Replace SERVICE with the name of your service.

    You can enable startup CPU boost during deployment using the command:

    gcloud  
    run  
    deploy  
    --image  
     IMAGE_URL 
      
    --cpu-boost

    Replace IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/hello:latest . If you use Artifact Registry, the repository REPO_NAME must already be created. The URL follows the format of LOCATION -docker.pkg.dev/ PROJECT_ID / REPO_NAME / PATH : TAG .

  2. You can disable startup CPU boost for a given service by using the following command:

    gcloud  
    run  
    services  
    update  
     SERVICE 
      
    --no-cpu-boost

    Replace SERVICE with the name of your service.

    You can disable startup CPU boost during deployment using the command:

    gcloud  
    run  
    deploy  
    --image  
     IMAGE_URL 
      
    --no-cpu-boost

YAML

  1. If you are creating a new service, skip this step. If you are updating an existing service, download its YAML configuration :

    gcloud  
    run  
    services  
    describe  
     SERVICE 
      
    --format  
     export 
      
    >  
    service.yaml
  2. Update the run.googleapis.com/startup-cpu-boost attribute by specifying 'true' to enable startup CPU boost or 'false' to disable:

     apiVersion 
     : 
      
     serving.knative.dev/v1 
     kind 
     : 
      
     Service 
     metadata 
     : 
      
     name 
     : 
      
      SERVICE 
     
     spec 
     : 
      
     template 
     : 
      
     metadata 
     : 
      
     annotations 
     : 
      
     run.googleapis.com/startup-cpu-boost 
     : 
      
     'true' 
    

    Replace SERVICE the name of your Cloud Run service.

  3. Create or update the service using the following command:

    gcloud  
    run  
    services  
    replace  
    service.yaml

Terraform

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands .

Add the following to a google_cloud_run_v2_service resource in your Terraform configuration:
  resource 
  
 "google_cloud_run_v2_service" 
  
 "default" 
  
 { 
  
 name 
  
 = 
  
 " SERVICE 
" 
  
 location 
  
 = 
  
 " REGION 
" 
  
 template 
  
 { 
  
 containers 
  
 { 
  
 image 
  
 = 
  
 "us-docker.pkg.dev/cloudrun/container/hello" 
  
 resources 
  
 { 
  
 startup_cpu_boost 
  
 = 
  
  CPU_BOOST 
 
  
 } 
  
 } 
  
 } 
 } 
 

Replace the following:

  • SERVICE : the name of your Cloud Run service.
  • REGION : the Google Cloud region—for example, europe-west1 .
  • CPU_BOOST : true to enable startup CPU boost or false to disable it.

View CPU settings

To view the current CPU settings for your Cloud Run service:

Console

  1. In the Google Cloud console, go to Cloud Run:

    Go to Cloud Run

  2. Click the service you are interested in to open the Service detailspage.

  3. Click the Revisionstab.

  4. In the details panel at the right, the CPU setting is listed under the Containertab.

gcloud

  1. Use the following command:

    gcloud  
    run  
    services  
    describe  
     SERVICE 
    
  2. Locate the CPU setting in the returned configuration.

Application threading and CPU utilization

When selecting a CPU limit greater than 1 vCPU, consider your application's threading model. When autoscaling, Cloud Run uses the average CPU utilization across all allocated CPUs. If your application is single-threaded, it may only fully utilize one core, which leads to a low average CPU utilization even under load. This can prevent CPU-based autoscaling from occurring as expected.

To avoid this behavior for a single-threaded application, if your memory requirements allow it, we recommend starting with 1 vCPU. This results in better CPU-based autoscaling. If higher memory needs force a multi-CPU selection for a single-threaded application, consider tuning your concurrency setting .

Create a Mobile Website
View Site in Mobile | Classic
Share by: