To understand the maximum concurrent requests per instance setting, read the concept document.
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 with Cloud Run, see Cloud Run IAM roles and Cloud Run IAM permissions. If your Cloud Run service interfaces with Google Cloud APIs, such as Cloud Client Libraries, see the service identity configuration guide. For more information about granting roles, see deployment permissions and manage access.
Configure maximum concurrent requests per instance
Any configuration change leads to the creation of a new revision. Subsequent revisions will also automatically get this configuration setting unless you make explicit updates to change it.
For Cloud Run services, you can set maximum concurrent requests per instance using the Google Cloud console, the gcloud command line, or using a .yaml file when you create a new service or deploy a new revision:
Console
In the Google Cloud console, go to Cloud Run:
Click Deploy container and select Service to configure a new service. If you are configuring an existing service, click the service, then click Edit and deploy new revision.
If you are configuring a new service, fill out the initial service settings page, then click Container(s), volumes, networking, security to expand the service configuration page.
Click the Container tab.
- Set the desired maximum concurrent requests per instance value in the text box Maximum requests per container.
Click Create or Deploy.
gcloud
To set maximum concurrent requests per instance, use the following command:
gcloud run services update SERVICE --concurrency CONCURRENCY
Replace
- SERVICE with the name of your service.
CONCURRENCY with the maximum number of concurrent requests per instance. For example the following sets a maximum of 1 concurrent requests:
gcloud run services update SERVICE --concurrency 1
Changing the maximum concurrent requests per instance of a given service will capture this setting in a new revision.
To revert to the default maximum concurrent requests per instance (80
), use the command
gcloud run services update SERVICE --concurrency default
Replace SERVICE with the name of the service you are configuring.
YAML
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
Update the
containerConcurrency
attribute:apiVersion: serving.knative.dev/v1 kind: Service metadata: name: SERVICE spec: template: metadata: name: REVISION spec: containerConcurrency: CONCURRENCY
Replace
- SERVICE with the name of your Cloud Run service
- IMAGE_URL with a reference to the container image, for
example,
us-docker.pkg.dev/cloudrun/container/hello:latest
. If you use Artifact Registry, the repository REPO_NAME must already be created. The URL has the shapeLOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG
- CONCURRENCY with the maximum number of concurrent requests per instance.
- 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
- Starts with
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, see Basic Terraform commands.
Add the following to a google_cloud_run_v2_service
resource in your Terraform
configuration, under template
. Replace 80
with your
desired maximum number of concurrent requests.
View concurrency settings
To view the current concurrency settings for your Cloud Run service:
Console
In the Google Cloud console, go to Cloud Run:
Click the service you are interested in to open the Service details page.
Click the Revisions tab.
In the details panel at the right, the concurrency setting is listed under the Container tab.
gcloud
Use the following command:
gcloud run services describe SERVICE
Locate the concurrency setting in the returned configuration.