Memory limits
You can provision Cloud 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 for Cloud Functions (1st gen) and Cloud Functions (2nd gen) are shown in the following table:
Memory (1st gen) | Memory (2nd gen) | CPU |
---|---|---|
128MB | 128 MiB | .083 vCPU |
256MB | 256 MiB | .167 vCPU |
512MB | 512 MiB | .333 vCPU |
1024MB | 1 GiB | .583 vCPU |
2048MB | 2 GiB | 1 vCPU |
4096MB | 4 GiB | 2 vCPU |
8192MB | 8 GiB | 2 vCPU |
Not available | 16 GiB | 4 vCPU |
Not available | 32 GiB | 8 vCPU |
By default, the memory allocated for a function is 256MB or 256 MiB depending on the Cloud Functions product version.
See Cloud 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 ...
Console
To set the allocated memory during function creation in the Google Cloud console:
- Go to the Cloud Functions Overview page in the Google Cloud console.
- Click Create function.
- Fill in the required fields for your function.
- Expand the Runtime, build... section at the end of the page and click the Runtime tab.
- In the Memory allocated field, select an amount of memory.
Set the number of vCPUs
You can configure 2nd gen functions with user-specified memory and (optional) vCPU. If you do not 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 beta functions deploy YOUR_FUNCTION_NAME \ --cpu=CPU \ --memory=MEMORY_LIMIT \ --gen2 \ FLAGS...
Console
To set the number of vCPUs during function creation in the Google Cloud console:
- Go to the Cloud Functions Overview page in the Google Cloud console.
- Click the name of your function to go to its Function details page.
- Click Edit.
- Expand the Runtime, build... section at the end of the page and click the Runtime tab.
- Under CPU, enter a value. It you supply a custom value, it will be added to the list.
- Click Deploy. This is a necessary step for your changes to go into effect.