You can provision your Cloud Run job with different amounts of memory. This page describes how to specify the amount of memory available for your job.
Understand memory usage
Cloud Run instances that exceed their allowed memory limit are terminated.
The following count towards the available memory of your instance:
- Running the job executable, because the executable must be loaded to memory
- Allocating memory in your job process
- Writing files to the file system
The size of the deployed container image does not count towards the available memory.
Set and update memory limits
You can set memory limits on Cloud Run jobs. By default, the memory allocated to each job is 512 MiB.
Required minimum CPUs
The amount of allocated memory you choose corresponds to an amount of allocated CPU for your job. When setting a memory limit, the following minimum CPU limits are required:
Memory | Minimum CPUs required |
---|---|
128 MiB | .083 vCPU |
256 MiB | .167 vCPU |
512 MiB | .333 vCPU |
1 GiB | .583 vCPU |
2 GiB | 1 vCPU |
More than 4 GiB | 2 vCPU |
More than 8 GiB | 4 vCPU |
More than 16 GiB | 6 vCPU |
More than 24 GiB | 8 vCPU |
Maximum amount of memory
The maximum amount of memory you can configure is
32 gibibyte (32 Gi
).
Minimum memory
The minimum amount of memory you can configure in the second generation execution environment is 512 MiB.
Required roles
To get the permissions that you need to configure Cloud Run jobs, ask your administrator to grant you the following IAM roles:
-
Cloud Run Developer (
roles/run.developer
) on the Cloud Run job -
Service Account User (
roles/iam.serviceAccountUser
) on the service identity
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 job 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 memory limits
You must specify a minimum of 512Mi for a Cloud Run job. To specify memory for a Cloud Run job:
Console
In the Google Cloud console, go to the Cloud Run jobs page:
Click Deploy container and select Job to fill out the initial job settings page. If you are configuring an existing job, select the job, then click Edit.
Click Container, variables and secrets, connections, security to expand the job properties page.
Click the Container tab.
- Select the desired memory size from the Memory drop-down list.
Click Create or Update.
gcloud
To set memory limits when you create a job:
gcloud run jobs create JOB_NAME --image IMAGE_URL --memory SIZE
Replace:
- JOB_NAME with the name of your job.
- IMAGE_URL with a reference to the container image, for
example,
us-docker.pkg.dev/cloudrun/container/job:latest
. - SIZE with the desired memory size. The format for size is a
fixed or floating point number followed by a unit:
G
orM
corresponding to gigabyte or megabyte, respectively, or use the power-of-two equivalents:Gi
orMi
corresponding to gibibyte or mebibyte respectively.
To set memory limits when you update a job:
gcloud run jobs update JOB_NAME --memory SIZE
YAML
If you are creating a new job, skip this step. If you are updating an existing job, download its YAML configuration:
gcloud run jobs describe JOB_NAME --format export > job.yaml
Update the
memory
attribute:apiVersion: run.googleapis.com/v1 kind: Job metadata: name: JOB spec: template: spec: template: spec: containers: - image: IMAGE resources: limits: memory: SIZE
Replace SIZE with the desired memory size, specifying a minimum of 512Mi. The format is a fixed or floating point number followed by a unit:
G
orM
corresponding to gigabyte or megabyte, respectively, or use the power-of-two equivalents:Gi
orMi
corresponding to gibibyte or mebibyte respectively.You can also specify more configuration such as environment variables or memory limits.
Update the existing job configuration:
gcloud run jobs replace job.yaml
View memory limit settings
To view the current memory limit settings for your Cloud Run job:
Console
In the Google Cloud console, go to the Cloud Run jobs page:
Click the job you are interested in to open the Job details page.
Click the Configuration tab.
Locate the memory limit setting in the configuration details.
gcloud
Use the following command:
gcloud run jobs describe JOB_NAME
Locate the memory limit setting in the returned configuration.