Setting Concurrency

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

Like any configuration change, setting the concurrency of a service leads to the creation of a new revision. Subsequent revisions will also automatically get the same concurrency setting unless you explicitly update it.

Console

Using the console, you can set concurrency at service creation or deployment time:

If you are creating a new service:

  1. Go to Cloud Run

  2. Create the service using the console as described in Deploying Services.

  3. After you specify the container image URL, the service name, and the location, click SHOW ADVANCED SETTINGS.

  4. Set the desired concurrency value in the text box Maximum requests per container:

    Set concurrency

If you are deploying a new revision of an existing service:

  1. Go to Cloud Run

  2. Locate the service you want to update in the services list, and click on it to open the details of that service.

  3. Click EDIT & DEPLOY NEW REVISION.

  4. Click SHOW ADVANCED SETTINGS.

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

Command line

To set concurrency, use the following command:

gcloud run services update SERVICE --concurrency CONCURRENCY

Replace

*SERVICE with the name of your service.

  • CONCURRENCYwith 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 concurrency of a given service will capture this setting in a new revision.

To revert to the default 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 beta run services describe --format yaml command, which yields 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.

To view and download configuration:

  1. gcloud beta run services describe SERVICE --format yaml > 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