This is the Archived version of the documentation. The free trial period ended on Sept. 30, 2021.

See the GA version documentation for details about installing Cloud Run for Anthos as an Anthos fleet component with Anthos Service Mesh.

Setting concurrency

Learn how to set the maximum number of requests that can be processed simultaneously by a given container instance in Cloud Run for Anthos. Learn more about concurrency.

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 configure concurrency settings using the Cloud console, or the Google Cloud CLI when you deploy a new service or update an existing service and deploy a revision:

Console

  1. Go to Cloud Run for Anthos in the Cloud console:

    Go to Cloud Run for Anthos

  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 & Deploy New Revision.

  3. Under Advanced settings, click Container.

    image

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

  5. Click Next to continue to the next section.

  6. In the Configure how this service is triggered section, select which connectivity you would like to use to invoke the service.

  7. Click Create to deploy the image to Cloud Run for Anthos and wait for the deployment to finish.

Command line

  • For existing services, set the maximum number of concurrent requests by running the gcloud run services update command with the --concurrency parameter:

    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. Specify default to clear any concurrency settings: --concurrency default.
  • For new services, set the maximum number of concurrent requests by running the gcloud run deploy command with the --concurrency parameter:

    gcloud run deploy SERVICE --image=IMAGE_URL --concurrency CONCURRENCY
    

    Replace:

    • SERVICE with the name of your service.
    • IMAGE_URL with a reference to the container image, for example, gcr.io/myproject/my-image:latest.
    • CONCURRENCY with the maximum number of concurrent requests per container instance. Specify default to clear any concurrency settings: --concurrency default.

YAML

You can download the configuration of an existing service into a YAML file with the gcloud run services describe command by using the --format=export flag. You can then modify that YAML file and deploy those changes with the gcloud beta run services replace command. You must ensure that you modify only the specified attributes.

  1. Download the configuration of your service into a file named service.yaml on local workspace:

    gcloud run services describe SERVICE --format export > service.yaml

    Replace SERVICE with the name of your Cloud Run for Anthos service.

  2. In your local file, 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 for Anthos service
    • CONCURRENCY with the maximum number of concurrent requests per container instance. Specify default to clear the concurrency settings: --concurrency default.
  3. Replace the service with its new configuration using the following command:

    gcloud beta run services replace service.yaml