This page describes how to specify the number of CPUs to allocate for each Cloud Run container instance. By default Cloud Run container instances are allocated 1 CPU instance. You can change this number.
Setting and updating CPU allocation
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.
By default, 1 CPU is allocated for each container instance. You can set CPU allocation using the Cloud Console, the gcloud command line, or a YAML file when you create a new service or deploy a new revision:
Console
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.
Under Advanced Settings, click Container.
Select the desired CPU allocation from the dropdown list. Select a value of
1
,2
, or4
vCPUs. (Note that using 4 vCPUs requires you to use a minimum of 2 GiB memory.).Click Create or Deploy.
Command line
You can update the memory allocation of a given service by using the following command:
gcloud run services update SERVICE --cpu CPU
Replace SERVICE with the name of your service and CPU
with the desired CPU allocation. Specify the value 1
, 2
, or 4
vCPUs. (Note that using 4 vCPUs
requires you to use a minimum of 2 GiB memory.).
You can also set CPU allocation 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,gcr.io/myproject/my-image:latest
.- CPU with the values described above.
YAML
You can download and view existing service configuration 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 beta 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: spec: containers: - image: IMAGE resources: limits: cpu: CPU
Replace
- SERVICE with the name of your Cloud Run service
- IMAGE with the URL of your container image.
- CPU with the desired CPU value.
Specify the value
1
,2
, or4
vCPUs. (Note that using 4 vCPUs requires you to use a minimum of 2 GiB memory.).
Replace the service with its new configuration using the following command:
gcloud beta run services replace service.yaml