Configure memory and vCPU limits

You can provision Cloud Run functions with different amounts of memory to control the limit on how much memory a function can use. The amount of allocated memory you choose corresponds to an amount of allocated CPU for your function. Available memory and CPU tiers are shown in the following table:

Memory CPU
128 MiB .083 vCPU
256 MiB .167 vCPU
512 MiB .333 vCPU
1 GiB .583 vCPU
2 GiB 1 vCPU
4 GiB 2 vCPU
8 GiB 2 vCPU
16 GiB 4 vCPU
32 GiB 8 vCPU

By default, the memory allocated for a function is 256MB or 256 MiB depending on the Cloud Run functions product version.

See Cloud Run functions Pricing for information about costs associated with memory and CPU allocations.

Set a memory limit

You can set a function's allocated memory at deployment using the Google Cloud CLI or the Google Cloud console:

gcloud

If you are deploying a function using the gcloud CLI, use the --memory flag:

gcloud functions deploy YOUR_FUNCTION_NAME --memory=MEMORY_LIMIT ...

See the Google Cloud CLI documentation for example values for the --memory flag.

Console

To set the allocated memory during function creation in the Google Cloud console:

  1. Go to the Cloud Run functions Overview page in the Google Cloud console.
  2. Click Create function.
  3. Fill in the required fields for your function.
  4. Expand the Runtime, build... section at the end of the page and click the Runtime tab.
  5. In the Memory allocated field, select an amount of memory.
  6. Click Next.
  7. Click Deploy.

Set the number of vCPUs

You can configure functions with user-specified memory and (optional) vCPU. If you don't specify vCPU, then it is automatically determined based on the memory you choose. Our default combinations are optimized for common workloads, but you can override the vCPU amount if needed.

If you change the amount of memory for a function, the vCPU will be recalculated accordingly. Be sure to include the amount of vCPU any time you want a non-default memory / vCPU configuration.

You can set a function's number of available vCPUs at deployment using the Google Cloud CLI or the Google Cloud console:

gcloud

You can set the number of available vCPUs using the --cpu flag:

gcloud functions deploy YOUR_FUNCTION_NAME \
--cpu=CPU \
--memory=MEMORY_LIMIT \
--gen2 \
FLAGS...

See the Google Cloud CLI documentation for example values for the --cpu flag.

Console

To set the number of vCPUs during function creation in the Google Cloud console:

  1. Go to the Cloud Run functions Overview page in the Google Cloud console.
  2. Click the name of your function to go to its Function details page.
  3. Click Edit.
  4. Expand the Runtime, build... section at the end of the page and click the Runtime tab.
  5. Under CPU, enter a value. It you supply a custom value, it will be added to the list.
  6. Click Next.
  7. Click Deploy.