教程:为微服务应用程序设置自动缩放功能Tutorial: Set up autoscale for microservice applications

自动缩放是 Azure Spring Cloud 的一种内置功能,可帮助微服务应用程序在需求更改时发挥最佳性能。Autoscale is a built-in feature of Azure Spring Cloud that helps microservice applications perform their best when demand changes. 这包括修改虚拟 CPU、内存和应用实例的数量。This includes modifying the number of virtual CPUs, memory, and app instances. 本文介绍如何使用 Azure 门户或 Azure CLI 为应用程序设置自动缩放设置。This article describes how to set up Autoscale settings for your applications using the Azure portal or the Azure CLI.

先决条件Prerequisites

若要遵循这些过程进行操作,需要:To follow these procedures, you need:

  1. 登录 Azure 门户Sign in to the Azure portal.
  2. 转到 Azure Spring Cloud 的“概览”页。Go to the Azure Spring Cloud Overview page.
  3. 选择包含服务的资源组。Select the resource group that contains your service.
  4. 在左侧导航窗格上菜单中的“设置”下选择“应用”选项卡。 Select the Apps tab under Settings in the menu on the left navigation pane.
  5. 选择要为其设置自动缩放功能的应用程序。Select the application for which you want to set up Autoscale. 在此示例中,选择名为 demo 的应用程序。In this example, select the application named demo. 然后会看到应用程序的“概览”页。You should then see the application's Overview page.
  6. 转到左侧导航窗格上菜单中的“设置”下的“横向扩展”选项卡。 Go to the Scale out tab under Settings in the menu on the left navigation pane.
  7. 选择要设置自动缩放功能的部署。Select the deployment you want to set up Autoscale. 你应会看到以下部分中所示的自动缩放选项。You should see options for Autoscale shown in the following section.

自动缩放菜单

在 Azure 门户中为应用程序设置自动缩放设置Set up Autoscale settings for your application in the Azure portal

自动缩放需求管理有两个选项:There are two options for Autoscale demand management:

  • 手动缩放:保持固定的实例计数。Manual scale: Maintains a fixed instance count. 在“标准”层中,最多可横向扩展到 500 个实例。In the Standard tier, you can scale out to a maximum of 500 instances. 此值更改微服务应用程序的单独运行实例的数目。This value changes the number of separate running instances of the microservice application.
  • 自定义自动缩放:根据任何指标按任何计划进行缩放。Custom autoscale: Scales on any schedule, based on any metrics.

在 Azure 门户中,选择所需缩放方式。In the Azure portal, choose how you want to scale. 下图显示“自定义自动缩放”选项和模式设置。The following figure shows the Custom autoscale option and mode settings.

自定义自动缩放

在 Azure CLI 中为应用程序设置自动缩放设置Set up Autoscale settings for your application in Azure CLI

还可以使用 Azure CLI 设置自动缩放模式。You can also set Autoscale modes using the Azure CLI. 以下命令创建自动缩放设置和自动缩放规则。The following commands create an Autoscale setting and an Autoscale rule.

  • 创建自动缩放设置Create Autoscale setting
    az monitor autoscale create -g demo-rg --resource /subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/demo-rg/providers/Microsoft.AppPlatform/Spring/autoscale/apps/demo/deployments/default --name demo-setting --min-count 1 --max-count 5 --count 1
    
  • 创建自动缩放规则Create Autoscale rule
    az monitor autoscale rule create -g demo-rg --autoscale-name demo-setting --scale out 1 --cooldown 1 --condition "tomcat.global.request.total.count > 100 avg 1m where AppName == demo and Deployment == default"
    

升级到标准层Upgrade to the Standard tier

如果在使用基本层,且受其中一项或多项限制约束,则可升级到标准层。If you are on the Basic tier and constrained by one or more of these limits, you can upgrade to the Standard tier. 若要执行此操作,请先选择“标准层”列,然后单击“升级”按钮,转到“定价层”菜单。To do this, go to the Pricing tier menu by first selecting the Standard tier column and the clicking the Upgrade button.

后续步骤Next steps