Configure memory limits

This page describes how to set memory limits.

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 application executable (as the executable must be loaded to memory)
  • Allocating memory in your application process
  • Writing files to the filesystem

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

When setting a memory limit, the following minimum CPU limits are required:

Memory Minimum CPUs required
More than 4 GiB 2
More than 8 GiB 4
More than 16 GiB 6
More than 24 GiB 8

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:

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

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

    Go to Cloud Run

  2. 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.

  3. Click Container, variables and secrets, connections, security to expand the job properties page.

  4. Click the Container tab.

    image

    • Select the desired memory size from the Memory drop-down list.
  5. Click Create or Update.

gcloud

  1. 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 or M corresponding to gigabyte or megabyte, respectively, or use the power-of-two equivalents: Gi or Mi corresponding to gibibyte or mebibyte respectively.
  2. To set memory limits when you update a job:

    gcloud run jobs update JOB_NAME --memory SIZE

YAML

  1. 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
  2. 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 or M corresponding to gigabyte or megabyte, respectively, or use the power-of-two equivalents: Gi or Mi corresponding to gibibyte or mebibyte respectively.

    You can also specify more configuration such as environment variables or memory limits.

  3. 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

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

    Go to Cloud Run jobs

  2. Click the job you are interested in to open the Job details page.

  3. Click the Configuration tab.

  4. Locate the memory limit setting in the configuration details.

gcloud

  1. Use the following command:

    gcloud run jobs describe JOB_NAME
  2. Locate the memory limit setting in the returned configuration.