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 Happens When You Don’t Maintain Your Furnace - Appleby Systems
Capitulations | Shared heritage -
Radikale Landküche am Landgut Schönwalde
Froedtert Billing Phone Number
Danatar Gym
Prosper TX Visitors Guide - Dallas Fort Worth Guide
Ati Capstone Orientation Video Quiz
Tx Rrc Drilling Permit Query
Trade Chart Dave Richard
Owatc Canvas
Snowflake Activity Congruent Triangles Answers
Nestle Paystub
Lost Pizza Nutrition
Bme Flowchart Psu
Why Is Stemtox So Expensive
Colts seventh rotation of thin secondary raises concerns on roster evaluation
Simon Montefiore artikelen kopen? Alle artikelen online
Michaels W2 Online
Walmart Double Point Days 2022
Foxy Brown 2025
Swgoh Blind Characters
Orange Pill 44 291
Katie Sigmond Hot Pics
Never Give Up Quotes to Keep You Going
Ezel Detailing
Jc Green Obits
Aes Salt Lake City Showdown
Rust Belt Revival Auctions
Gas Buddy Prices Near Me Zip Code
Macu Heloc Rate
Craig Woolard Net Worth
Speedstepper
Movies - EPIC Theatres
Rubmaps H
Rlcraft Toolbelt
Smartfind Express Henrico
Envy Nails Snoqualmie
Σινεμά - Τι Ταινίες Παίζουν οι Κινηματογράφοι Σήμερα - Πρόγραμμα 2024 | iathens.gr
Tamilyogi Ponniyin Selvan
Family Fare Ad Allendale Mi
Danielle Ranslow Obituary
Postgraduate | Student Recruitment
Traumasoft Butler
Garland County Mugshots Today
Xre 00251
Keci News
Okta Login Nordstrom
Stephen Dilbeck, The First Hicks Baby: 5 Fast Facts You Need to Know
Service Changes and Self-Service Options
The Missile Is Eepy Origin
How to Choose Where to Study Abroad
Gainswave Review Forum
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.