Azure 虚拟机规模集自动缩放概述Overview of autoscale with Azure virtual machine scale sets

Azure 虚拟机规模集可以自动增加或减少运行应用程序的 VM 实例数。An Azure virtual machine scale set can automatically increase or decrease the number of VM instances that run your application. 这种自动且弹性的行为可以减少监视和优化应用程序性能所需的管理开销。This automated and elastic behavior reduces the management overhead to monitor and optimize the performance of your application. 创建规则,用于定义提供正面客户体验而可接受的性能。You create rules that define the acceptable performance for a positive customer experience. 如果满足定义的这些阈值,自动缩放规则会采取措施来调整规模集的容量。When those defined thresholds are met, autoscale rules take action to adjust the capacity of your scale set. 还可以计划事件,以便在固定的时间自动增加或减少规模集的容量。You can also schedule events to automatically increase or decrease the capacity of your scale set at fixed times. 本文概述所提供的性能指标,以及自动缩放可以执行的操作。This article provides an overview of which performance metrics are available and what actions autoscale can perform.

自动缩放的好处Benefits of autoscale

如果应用程序需求提高,规模集中 VM 实例上的负载将会增大。If your application demand increases, the load on the VM instances in your scale set increases. 如果这种负载增大持续稳定,而不只是短暂的需求,那么可以配置自动缩放规则来增加规模集中的 VM 实例数。If this increased load is consistent, rather than just a brief demand, you can configure autoscale rules to increase the number of VM instances in the scale set.

创建这些 VM 实例并部署应用程序后,规模集会开始通过负载均衡器将流量分配到这些实例和应用程序。When these VM instances are created and your applications are deployed, the scale set starts to distribute traffic to them through the load balancer. 可以控制要监视的指标(例如 CPU 或内存)、应用程序负载必须满足给定阈值的时间,以及要添加到规模集的 VM 实例数。You control what metrics to monitor, such as CPU or memory, how long the application load must meet a given threshold, and how many VM instances to add to the scale set.

在夜间或周末,应用程序需求可能会降低。On an evening or weekend, your application demand may decrease. 如果这种负载降低在一段时间内持续稳定,可以配置自动缩放规则来减少规模集中的 VM 实例数。If this decreased load is consistent over a period of time, you can configure autoscale rules to decrease the number of VM instances in the scale set. 这种缩减措施可以减少运行规模集所需的成本,因为只要运行满足当前需求所需的实例数。This scale-in action reduces the cost to run your scale set as you only run the number of instances required to meet the current demand.

使用基于主机的指标Use host-based metrics

可以创建内置于 VM 实例提供的主机指标中的自动缩放规则。You can create autoscale rules that built-in host metrics available from your VM instances. 通过主机指标可以洞察规模集中 VM 实例的性能,而无需安装或配置附加的代理和数据集合。Host metrics give you visibility into the performance of the VM instances in a scale set without the need to install or configure additional agents and data collections. 使用这些指标的自动缩放规则可以增加或减少 VM 实例数目来响应 CPU 使用率、内存需求或磁盘访问。Autoscale rules that use these metrics can scale out or in the number of VM instances in response to CPU usage, memory demand, or disk access.

可通过以下工具之一创建使用基于主机的指标的自动缩放规则:Autoscale rules that use host-based metrics can be created with one of the following tools:

若要创建使用更详细性能指标的自动缩放规则,可在 VM 实例上安装并配置 Azure 诊断扩展To create autoscale rules that use more detailed performance metrics, you can install and configure the Azure diagnostics extension on VM instances.

使用基于主机的指标和 Azure 诊断扩展中的来宾内 VM 指标的自动缩放规则可使用以下配置设置。Autoscale rules that use host-based metrics, in-guest VM metrics with the Azure diagnostic extension can use the following configuration settings.

指标源Metric sources

自动缩放规则可以使用来自以下源之一的指标:Autoscale rules can use metrics from one of the following sources:

指标源Metric source 使用案例Use case
当前规模集Current scale set 适用于无需附加代理即可安装或配置的基于主机的指标。For host-based metrics that do not require additional agents to be installed or configured.
存储帐户Storage account Azure 诊断扩展会将性能指标写入 Azure 存储,然后,可使用 Azure 存储来触发自动缩放规则。The Azure diagnostic extension writes performance metrics to Azure storage that is then consumed to trigger autoscale rules.
服务总线队列Service Bus Queue 应用程序或其他组件可将 Azure 服务总线队列中的消息传输到触发器规则。Your application or other components can transmit messages on an Azure Service Bus queue to trigger rules.

自动缩放规则条件Autoscale rule criteria

创建自动缩放规则时,可使用以下基于主机的指标。The following host-based metrics are available for use when you create autoscale rules. 如果使用 Azure 诊断扩展,请定义要通过自动缩放规则监视和使用的指标。If you use the Azure diagnostic extension, you define which metrics to monitor and use with autoscale rules.

指标名称Metric name
CPU 百分比Percentage CPU
网络传入Network In
网络传出Network Out
磁盘读取字节数Disk Read Bytes
磁盘写入字节数Disk Write Bytes
磁盘读取操作次数/秒Disk Read Operations/Sec
磁盘写入操作次数/秒Disk Write Operations/Sec
剩余 CPU 信用额度CPU Credits Remaining
已用 CPU 信用额度CPU Credits Consumed

创建用于监视给定指标的自动缩放规则时,规则会检查以下指标聚合操作之一:When you create autoscale rules to monitor a given metric, the rules look at one of the following metrics aggregation actions:

聚合类型Aggregation type
平均值Average
最小值Minimum
最大值Maximum
总计Total
最后一个Last
计数Count

使用以下运算符之一将指标与定义的阈值进行比较时,会触发自动缩放规则:The autoscale rules are then triggered when the metrics are compared against your defined threshold with one of the following operators:

运算符Operator
大于Greater than
大于或等于Greater than or equal to
小于Less than
小于等于Less than or equal to
等于Equal to
不等于Not equal to

规则触发时的操作Actions when rules trigger

自动缩放规则触发时,规模集可通过以下方式之一自动缩放:When an autoscale rule triggers, your scale set can automatically scale in one of the following ways:

缩放操作Scale operation 使用案例Use case
增加计数Increase count by 要创建的 VM 实例的固定数目。A fixed number of VM instances to create. 在 VM 数量较少的规模集中很有用。Useful in scale sets with a smaller number of VMs.
增加百分比Increase percent by VM 实例的增加数量百分比。A percentage-based increase of VM instances. 非常适用于较大的规模集,在其中按固定数量增加 VM 无法明显提高性能。Good for larger scale sets where a fixed increase may not noticeably improve performance.
增加计数至Increase count to 创建任意数量的 VM 实例来达到所需的最大数量。Create as many VM instances are required to reach a desired maximum amount.
减少计数Decrease count by 要删除的 VM 实例的固定数目。A fixed number of VM instances to remove. 在 VM 数量较少的规模集中很有用。Useful in scale sets with a smaller number of VMs.
减少百分比Decrease percent by VM 实例的减少数量百分比。A percentage-based decrease of VM instances. 非常适用于较大的规模集,在其中按固定数量增加 VM 无法明显降低资源消耗和成本。Good for larger scale sets where a fixed increase may not noticeably reduce resource consumption and costs.
减少计数至Decrease count to 删除任意数量的 VM 实例来达到所需的最小数量。Remove as many VM instances are required to reach a desired minimum amount.

Azure 诊断扩展中的来宾内 VM 指标In-guest VM metrics with the Azure diagnostics extension

Azure 诊断扩展是在 VM 实例中运行的代理。The Azure diagnostics extension is an agent that runs inside a VM instance. 该代理可监视性能指标并将其保存到 Azure 存储。The agent monitors and saves performance metrics to Azure storage. 这些性能指标包含有关 VM 状态的更详细信息,例如磁盘的 AverageReadTime,或 CPU 的 PercentIdleTimeThese performance metrics contain more detailed information about the status of the VM, such as AverageReadTime for disks or PercentIdleTime for CPU. 可以根据对 VM 性能的更详细认知,而不仅仅是 CPU 使用率或内存消耗量的百分比,来创建自动缩放规则。You can create autoscale rules based on a more detailed awareness of the VM performance, not just the percentage of CPU usage or memory consumption.

若要使用 Azure 诊断扩展,必须为 VM 实例创建 Azure 存储帐户,安装 Azure 诊断代理,然后将 VM 配置为向存储帐户流式传输特定的性能计数器。To use the Azure diagnostics extension, you must create Azure storage accounts for your VM instances, install the Azure diagnostics agent, then configure the VMs to stream specific performance counters to the storage account.

有关详细信息,请参阅有关如何在 Linux VMWindows VM 上启用 Azure 诊断扩展的文章。For more information, see the articles for how to enable the Azure diagnostics extension on a Linux VM or Windows VM.

计划的自动缩放Scheduled autoscale

还可以基于计划创建自动缩放规则。You can also create autoscale rules based on schedules. 使用这些基于计划的规则可在固定的时间自动缩放 VM 实例的数目。These schedule-based rules allow you to automatically scale the number of VM instances at fixed times. 使用基于性能的规则时,在触发自动缩放规则和预配新的 VM 实例之前,应用程序的性能可能会受影响。With performance-based rules, there may be a performance impact on the application before the autoscale rules trigger and the new VM instances are provisioned. 如果能够预见到这种需求,可以预配更多的 VM 实例,并使其随时可用于满足更多的客户用途和应用程序的需求。If you can anticipate such demand, the additional VM instances are provisioned and ready for the additional customer use and application demand.

以下示例是能够从基于计划的自动缩放规则中受益的情景:The following examples are scenarios that may benefit the use of schedule-based autoscale rules:

  • 在工作日开始且客户需求增大时自动增加 VM 实例数。Automatically scale out the number of VM instances at the start of the work day when customer demand increases. 在工作日结束且应用程序用量较低时,在夜间自动减少 VM 实例数以最大程度地降低资源成本。At the end of the work day, automatically scale in the number of VM instances to minimize resource costs overnight when application use is low.
  • 如果某个部门在月份或财政周期的某些时段重度使用某个应用程序,则自动增加 VM 实例数来适应额外的需求。If a department uses an application heavily at certain parts of the month or fiscal cycle, automatically scale the number of VM instances to accommodate their additional demands.
  • 开展市场营销活动、促销或假日销售时,可以在预测客户需求之前自动增加 VM 实例数。When there is a marketing event, promotion, or holiday sale, you can automatically scale the number of VM instances ahead of anticipated customer demand.

后续步骤Next steps

可通过以下工具之一创建使用基于主机的指标的自动缩放规则:You can create autoscale rules that use host-based metrics with one of the following tools:

有关如何管理 VM 实例的信息,请参阅使用 Azure PowerShell 管理虚拟机规模集For information on how to manage your VM instances, see Manage virtual machine scale sets with Azure PowerShell.