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 increase this using any integer value up to a maximum of 8 CPUs.
CPU and memory
The following are minimum memory requirements for CPUs:
CPUs | Minimum memory |
---|---|
4 | 2 GiB |
6 | 3 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.01. Any value above 1 must be an integer value. 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 . |
CPU allocated | CPU allocation must be set to CPU allocated only during request processing. |
Execution environment | You must use the first generation execution environment. |
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
In the Google Cloud console, go to Cloud Run:
Click Create Service if you are configuring a new service you are deploying to. If you are configuring an existing service, click on the service, then click Edit and Deploy New Revision.
If you are configuring a new service, fill out the initial service settings page as desired, then click Container, Networking, Security to expand the service configuration page.
Click the Container tab.
- Select the desired CPU limit from the dropdown
list, using Custom if you want to use less than 1 CPU. Select a value of
1
,2
,4
,6
, or8
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.)
- Select the desired CPU limit from the dropdown
list, using Custom if you want to use less than 1 CPU. Select a value of
Click Create or Deploy.
Command line
You can update the CPU limits for a given service by using the following command:
gcloud run services update SERVICE --cpu CPU
Replace
- SERVICE with the name of your service
- CPU with the desired CPU limit. Specify the value
1
,2
,4
,6
, or8
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
- 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 has the shapeREGION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG
. - CPU with the value
1
,2
,4
,6
, or8
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
You can download and view existing service configurations using the
gcloud run services describe --format export
command, which yields
cleaned results in YAML format.
You can then modify the fields described below and
upload the modified YAML using the gcloud run services replace
command.
Make sure you only modify fields as documented.
To view and download the configuration:
gcloud run services describe SERVICE --format export > service.yaml
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
- SERVICE with the name of your Cloud Run service
- 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 has the shapeREGION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG
- CPU with the desired CPU limit value.
Specify the value
1
,2
,4
,6
, or8
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
- Starts with
Replace the service with its new configuration 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.
The following google_cloud_run_v2_service
resource specifies a CPU limit
under template.containers.resources.limits
. Replace
1
with your desired CPU count.
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.
You can enable or disable startup CPU boost using Google Cloud console or Google Cloud CLI.
Console
In the Google Cloud console, go to Cloud Run:
Click Create Service if you are configuring a new service you are deploying to. If you are configuring an existing service, click on the service, then click Edit and Deploy New Revision.
If you are configuring a new service, fill out the initial service settings page as desired, then click Container, Networking, Security to expand the service configuration page.
Click the Container tab.
- To enable startup CPU boost select the check box Startup CPU boost. To disable this feature, deselect the checkbox.
Click Create or Deploy.
Command line
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 has the shapeREGION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG
.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
You can download and view existing service configurations using the
gcloud run services describe --format export
command, which yields
cleaned results in YAML format.
You can then modify the fields described below and
upload the modified YAML using the gcloud run services replace
command.
Make sure you only modify fields as documented.
To view and download the configuration:
gcloud run services describe SERVICE --format export > service.yaml
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 with the name of your Cloud Run service
Replace the service with its new configuration using the following command:
gcloud run services replace service.yaml
View CPU settings
To view the current CPU settings for your Cloud Run service:
Console
In the Google Cloud console, go to Cloud Run:
Click the service you are interested in to open the Service details page.
Click the Revisions tab.
In the details panel at the right, the CPU setting is listed under the Container tab.
Command line
Use the following command:
gcloud run services describe SERVICE
Locate the CPU setting in the returned configuration.