Configure memory limits  |  Cloud Run Documentation  |  Google Cloud (2024)

This page describes how to set memory limits.

Understand memory usage

Cloud Run instances that exceed their allowed memory limit areterminated.

The following count towards the available memory of your instance:

  • Running the application executable (as the executable must be loaded tomemory)
  • Allocating memory in your application process
  • Writing files to the filesystem

The size of the deployed container image does not count towards the availablememory.

Set and update memory limits

You can set memory limits on Cloud Run services. Bydefault, the memory allocated to each instance of a revision is512 MiB.

Required minimum CPUs

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

MemoryMinimum CPUs required
More than 4 GiB2
More than 8 GiB4
More than 16 GiB6
More than 24 GiB8

Maximum amount of memory

The maximum amount of memory you can configure is32 gibibyte (32 Gi).

You can enforce a maximum memory limit by usingcustom organization policies.

Minimum memory

The minimum memory setting varies depending on whether you usefirst generation or second generationexecution environment:

  • 128 MiB for first generation
  • 512 MiB for second generation

Required roles

To get the permissions that you need to configure and deploy Cloud Run services, ask your administrator to grant you the following IAM roles:

  • Cloud Run Developer (roles/run.developer) on the Cloud Run service
  • Service Account User (roles/iam.serviceAccountUser) on the service identity

For a list of IAM roles and permissions that are associated withCloud Run, seeCloud Run IAM rolesand Cloud Run IAM permissions.If your Cloud Run service interfaces withGoogle Cloud APIs, such as Cloud Client Libraries, see theservice identity configuration guide.For more information about granting roles, seedeployment permissionsand manage access.

Configure memory limits

Any configuration change leads to thecreation of a new revision. Subsequent revisions will also automatically getthis configuration setting unless you make explicit updates to change it.

For Cloud Run services, you can set memory limits using the Google Cloud console, the gcloudcommand line, or a YAML file when you create a new service ordeploy a new revision:

Console

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

    Go to Cloud Run

  2. Click Deploy container and select Service to configure anew service. If you are configuring an existing service, click theservice, then click Edit and deploy new revision.

  3. If you are configuring a new service, fill out the initial servicesettings page, then click Container(s), volumes, networking, security to expand theservice configuration page.

  4. Click the Container tab.

    Configure memory limits | Cloud Run Documentation | Google Cloud (1)

    • Select the desired memory size from the Memory dropdown list.
  5. Click Create or Deploy.

gcloud

You can update the memory allocationof a given service by using the following command:

gcloud run services update SERVICE --memory SIZE

Replace SERVICE with the name of your service and SIZE with the desiredmemory size. The format for size is a fixed or floating point number followedby a unit: G or M corresponding to gigabyte or megabyte,respectively, or use the power-of-two equivalents: Gi or Micorresponding to gibibyte or mebibyte respectively.

You can also set memory limits duringdeployment using the command:

gcloud run deploy --image IMAGE_URL --memory SIZE

Replace

  • IMAGE_URL with a reference to the container image, forexample, us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry,the repository REPO_NAME mustalready be created. The URL has the shape LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG.
  • SIZE with the values described above.

YAML

  1. If you are creating a new service, skip this step.If you are updating an existing service, download its YAML configuration:

    gcloud run services describe SERVICE --format export > service.yaml
  2. Update the memory attribute:

    apiVersion: serving.knative.dev/v1kind: Servicemetadata: name: SERVICEspec: template: metadata: name: REVISION spec: containers: - image: IMAGE resources: limits: memory: SIZE

    Replace

    • SERVICE with the name of your Cloud Run service
    • IMAGE_URL with a reference to the container image, forexample, us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry,the repository REPO_NAME mustalready be created. The URL has the shape LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG
    • SIZE with the desired memory size.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 Micorresponding to gibibyte or mebibyte respectively.
    • REVISION with a new revision name or delete it (if present). If you supply a new revision name, it must meet the following criteria:
      • Starts with SERVICE-
      • Contains only lowercase letters, numbers and -
      • Does not end with a -
      • Does not exceed 63 characters
  3. Create or update the service using the following command:

    gcloud run services replace service.yaml

Terraform

To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.

Add the following to a google_cloud_run_v2_service resource in your Terraformconfiguration, under template.containers.resources.limits. Replace 512Mi with yourservice's desired memory limit.

resource "google_cloud_run_v2_service" "default" { name = "cloudrun-service-memory-limits" location = "us-central1" template { containers { image = "us-docker.pkg.dev/cloudrun/container/hello" resources { limits = { # Memory usage limit (per container) memory = "512Mi" } } } }}

Optimize memory for services

For a Cloud Run service, you can determine the peak memory requirement for a service using thefollowing: (Standing Memory) + (Memory per Request) * (Service Concurrency)

Accordingly,

  • If you raise the concurrency of your service, you should alsoincrease the memory limit to account for peak usage.

  • If you lower the concurrency of your service, consider reducing the memorylimit to save on memory usage costs.

For more guidance on minimizing per request memory usage readDevelopment Tips on Global Variables.

View memory limit settings

To view the current memory limit settings for yourCloud Run service:

Console

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

    Go to Cloud Run

  2. Click the service you are interested in to open the Service detailspage.

  3. Click the Revisions tab.

  4. In the details panel at the right, the memory limit settingis listed under the Container tab.

gcloud

  1. Use the following command:

    gcloud run services describe SERVICE
  2. Locate the memory limit setting in the returnedconfiguration.

Configure memory limits  |  Cloud Run Documentation  |  Google Cloud (2024)
Top Articles
What Is a Credit Card Annual Fee?
The 3 Most Powerful Numbers In Numerology
Sound Of Freedom Harkins Casa Grande
Joes Barbershop Maricopa Az
Gimkit Enter Pin
How much does it cost to sell your Bitcoin?
Wsbtv Fish And Game Report
Skeleton Soldier Failed To Defend The Dungeon Wiki
Varsity Competition Results 2022
Reyes Holdings - 6th Largest Privately Owned Company in US
Ostedia
About iOS 18 Updates - Apple Support
Www.metaquest/Device Code
Huffington Horoscope Cancer
Pharmacies in Amsterdam (Apotheek) | Amsterdam.info
432-237-3514
Armslist Kansas City Missouri
Alabama Teachers Credit Union Albertville Al
What Channels Are Included In Spectrum Entertainment View
Phoenix Hotel ab 84 €. Hotels in London - KAYAK
Dwarf Fortress Polish Stones
Brimstone Sands Lost Easels
Onci Investorshub
Aabb Investorshub
Fighter Torso Ornament Kit
Waters Funeral Home | Baldwyn, MS Funeral Home & Cremation
Paperlesspay Talx Ingram
Is Chanel West Coast Pregnant Due Date
Levidia 2019
Carthago Chic C-Line PLUS ENKELE BEDDEN + HEFB - Campersite.nl - Campersite: campers en kampeerauto's, met campernieuws en -informatie, techniek, camperplaatsen, occasions, etc.
Mexican restaurant, butcher shop in El Paso receive low inspection scores: See the list
Pewdiepieisprettydarncool
World of Warships: Aslains Modpack - Alle Mods in einem Paket
Megared Rewards
Covers Ncaab Forum
Phoenix Rising Skilled Gaming
Mlm Urban Meaning
24Hrs Mcdonalds Near Me
Comment résoudre l'erreur « Could not resolve hostname: nodename nor servname provided, or not known » ?
Weilers Gentle Giants
Egusd Lunch Menu
Gluten Ease Walgreens
R. Kelly trial: A look at the key moments after star found guilty
Inloggen bij Fontys | Fontys
Fgo Spirit Root
Twoplustwo Forums
Sweaty Gta Names Tryhard Gamertags
R/Mommit
Paystub Portal Casper
Recent Vanderburgh County Arrest
Gegp Ihub
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 5962

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.