This page describes how to set memory limits.
Understanding memory usage
Cloud Run container instances that exceed their allowed memory limit are terminated.
The following count towards the available memory of your container 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.
Setting and updating memory limits
By default, the memory allocated to each container instance of a revision is 256MiB.
Like any configuration change, setting an memory limits leads to the creation of a new revision. Subsequent revisions will also automatically get this memory limit unless you make explicit updates to change it.
Click CREATE SERVICE if you are setting memory limits on a new service you are deploying to. If you are setting limits on an existing service, then click on the service, then click DEPLOY NEW REVISION.
Click SHOW OPTIONAL SETTINGS.
Select the desired memory size from the dropdown list.
Click Create or Deploy.
You can update the memory allocation of a given service by using the following command:
gcloud beta run services update [SERVICE] --memory [SIZE]
[SERVICE] with the name of your service and
[SIZE] with the desired
memory size. The format for size is a fixed or floating point number followed
by a unit:
K corresponding to gigabyte, megabyte, or kilobyte,
respectively, or use the power-of-two equivalents:
corresponding to gibibyte, mebibyte or kibibyte respectively.
When deploying to Cloud Run, the maximum amount of memory is 2 gibibyte (
When deploying to Cloud Run on GKE, the maximum amount of memory is limited by the configuration of your GKE cluster.
You can also set memory limits during deployment using the command:
gcloud beta run deploy --image gcr.io/[PROJECT-ID]/[IMAGE] --memory [SIZE]
[PROJECT-ID]with your GCP project ID.
[IMAGE]with the name of your image.
[SIZE]with the values described above.
The peak memory requirement for a service can be found using the following: (Standing Memory) + (Memory per Request) * (Service Concurrency)
If you raise the concurrency of your service, you should also increase the memory limit to account for peak usage.
If you lower the concurrency of your service, consider reducing the memory limit to save on memory usage costs.
For more guidance on minimizing per request memory usage read Development Tips on Global Variables.