Setting maximum concurrency

To understand the maximum concurrency setting, read the Concurrency concept document.

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.

You can set maximum concurrency using the Cloud Console, the gcloud command line, or using a .yaml file when you create a new service or deploy a new revision:

Console

  1. Go to Cloud Run

  2. Click Create Service if you are configuring a new service you are deploying to. If you are configuring an existing service, click on the service, then click Edit and Deploy New Revision.

  3. If you are configuring a new service, fill out the initial service settings page as desired, then click Next > Advanced settings to reach the service configuration page.

  4. Click the Container tab.

    image

  5. Set the desired maximum concurrency value in the text box Maximum requests per container.

  6. Click Create or Deploy.

Command line

To set maximum concurrency, 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 container instance. For example the following sets a maximum of 40 concurrent requests:

    gcloud run services update SERVICE --concurrency 40

Changing the maximum concurrency of a given service will capture this setting in a new revision.

To revert to the default maximum concurrency (80), use the command

gcloud run services update SERVICE --concurrency default

Replace SERVICE with the name of the service you are configuring.

YAML

You can download and view existing service configuration using the gcloud run services describe --format export command, which yields cleaned results in YAML format. You can then modify the fields described below and upload the modified YAML using the gcloud beta run services replace command. Make sure you only modify fields as documented.

  1. To view and download the configuration:

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

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: SERVICE
    spec:
      template:
        spec:
          containerConcurrency: CONCURRENCY

    Replace

    • SERVICE with the name of your Cloud Run service
    • IMAGE with the URL of your container image.
    • CONCURRENCY with the maximum number of concurrent requests per container instance.
  3. Replace the service with its new configuration using the following command:

    gcloud beta run services replace service.yaml

Viewing concurrency settings

To view the current concurrency settings for your service:

Console

  1. Go to Cloud Run

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

  3. Click the Revisions tab.

  4. In the details panel at the right, the concurrency setting is listed under the Container tab.

Command line

  1. Use the following command:

    gcloud run services describe SERVICE
  2. Locate the concurrency setting in the returned configuration.