Azure 中的自动缩放概述Overview of autoscale in Azure

本文介绍了 Azure 自动缩放是什么、其对用户的好处,以及如何开始使用它。This article describes what Azure autoscale is, its benefits, and how to get started using it.

Azure Monitor 自动缩放仅适用于虚拟机规模集云服务应用服务 - Web 应用API 管理服务Azure 数据资源管理器Azure Monitor autoscale applies only to Virtual Machine Scale Sets, Cloud Services, App Service - Web Apps, API Management services, and Azure Data Explorer Clusters.

备注

Azure 有两个自动缩放方法。Azure has two autoscale methods. 旧版自动缩放适用于虚拟机(可用性集)。An older version of autoscale applies to Virtual Machines (availability sets). 此功能的支持有限。若要获取更快速、更可靠的自动缩放支持,建议迁移到虚拟机规模集。This feature has limited support and we recommend migrating to virtual machine scale sets for faster and more reliable autoscale support. 本文提供了此旧技术的使用方法链接。A link on how to use the older technology is included in this article.

自动缩放是什么?What is autoscale?

自动缩放是指在处理应用程序负载时让适当数量的资源运行。Autoscale allows you to have the right amount of resources running to handle the load on your application. 当负载增加时,它可以添加资源来处理增加的负载;当资源空闲时,它可以删除资源以节省资金。It allows you to add resources to handle increases in load and also save money by removing resources that are sitting idle. 可以指定需要运行的实例的最小数目和最大数目,根据规则集自动添加或删除 VM。You specify a minimum and maximum number of instances to run and add or remove VMs automatically based on a set of rules. 设置最小数目可确保应用程序在没有负载的情况下也会运行。Having a minimum makes sure your application is always running even under no load. 设置最大数目是为了限制每小时可能会引发的总成本。Having a maximum limits your total possible hourly cost. 可以使用创建的规则在这两种极限之间自动缩放。You automatically scale between these two extremes using rules you create.

描述的自动缩放。

当满足规则条件时,将触发一个或多个自动缩放操作。When rule conditions are met, one or more autoscale actions are triggered. 可以添加和删除虚拟机,或执行其他操作。You can add and remove VMs, or perform other actions. 下面的概念关系图演示了此过程。The following conceptual diagram shows this process.

自动缩放流关系图

以下说明适用于上面的关系图的各个部分。The following explanation applies to the pieces of the previous diagram.

资源指标Resource Metrics

资源会发出指标,这些指标随后通过规则进行处理。Resources emit metrics, these metrics are later processed by rules. 指标通过不同方法发出。Metrics come via different methods. 虚拟机规模集使用 Azure 诊断代理提供的遥测数据,而 Web 应用和云服务的遥测则直接来自 Azure 基础结构。Virtual machine scale sets use telemetry data from Azure diagnostics agents whereas telemetry for Web apps and Cloud services comes directly from the Azure Infrastructure. 一些常用的统计信息包括:CPU 使用率、内存使用情况、线程计数、队列长度和磁盘使用情况。Some commonly used statistics include CPU Usage, memory usage, thread counts, queue length, and disk usage. 如需可用遥测数据的列表,请参阅自动缩放常用指标For a list of what telemetry data you can use, see Autoscale Common Metrics.

自定义指标Custom Metrics

还可以利用应用程序可以发出的自己的自定义指标。You can also leverage your own custom metrics that your application(s) may be emitting. 如果已将应用程序配置为向 Application Insights 发送指标,则可以利用这些指标来决定是否要进行缩放。If you have configured your application(s) to send metrics to Application Insights you can leverage those metrics to make decisions on whether to scale or not.

时间Time

基于计划的规则以 UTC 为基础。Schedule-based rules are based on UTC. 设置规则时,必须正确设置时区。You must set your time zone properly when setting up your rules.

规则Rules

此图仅显示了一个自动缩放规则,但用户可以有许多个这样的规则。The diagram shows only one autoscale rule, but you can have many of them. 可以根据自身情况所需创建复杂的、互相重叠的规则。You can create complex overlapping rules as needed for your situation. 规则类型包括Rule types include

  • 基于指标 - 例如,在 CPU 使用率超出 50% 时执行该操作。Metric-based - For example, do this action when CPU usage is above 50%.
  • 基于时间 - 例如,在给定时区的每个星期六的早晨 8 点触发 webhook。Time-based - For example, trigger a webhook every 8am on Saturday in a given time zone.

基于指标的规则会衡量应用程序负载,根据负载添加或删除 VM。Metric-based rules measure application load and add or remove VMs based on that load. 如果使用基于计划的规则,则当用户看到负载时间模式并且想要在负载可能升高或降低之前进行缩放时,完成相应的缩放。Schedule-based rules allow you to scale when you see time patterns in your load and want to scale before a possible load increase or decrease occurs.

操作和自动化Actions and automation

规则可以触发一个或多个类型的操作。Rules can trigger one or more types of actions.

  • 缩放 - 扩大或缩小 VMScale - Scale VMs in or out
  • 电子邮件 - 将电子邮件发送给订阅管理员、共同管理员和/或指定的其他电子邮件地址Email - Send email to subscription admins, co-admins, and/or additional email address you specify
  • 通过 webhook 自动操作 - 调用 webhook,在 Azure 内外触发多个复杂操作。Automate via webhooks - Call webhooks, which can trigger multiple complex actions inside or outside Azure. 在 Azure 中,可以启动 Azure 自动化 runbook、Azure 函数或 Azure 逻辑应用。Inside Azure, you can start an Azure Automation runbook, Azure Function, or Azure Logic App. 在 Azure 外的第三方 URL 示例包含 Slack 和 Twilio 之类的服务。Example third-party URL outside Azure include services like Slack and Twilio.

自动缩放设置Autoscale Settings

自动缩放使用下列术语和结构。Autoscale use the following terminology and structure.

  • 自动缩放设置:由自动缩放引擎读取,用于确定是进行扩展还是缩减。An autoscale setting is read by the autoscale engine to determine whether to scale up or down. 它包含一个或多个配置文件、目标资源的信息,以及通知设置。It contains one or more profiles, information about the target resource, and notification settings.

    • 自动缩放配置文件是以下项的组合:An autoscale profile is a combination of a:

      • 容量设置:表示实例数的最小值、最大值和默认值。capacity setting, which indicates the minimum, maximum, and default values for number of instances.

      • 规则集,其中的每个规则都包括一个触发器(时间或指标)和一个缩放操作(增加或缩减)。set of rules, each of which includes a trigger (time or metric) and a scale action (up or down).

      • 定期:表示自动缩放应在何时使此配置文件生效。recurrence, which indicates when autoscale should put this profile into effect.

        可以有多个配置文件,以应对不同的互相重叠的要求。You can have multiple profiles, which allow you to take care of different overlapping requirements. 例如,可以针对一天中的不同时间或者一周中的不同日期设置不同的自动缩放配置文件。You can have different autoscale profiles for different times of day or days of the week, for example.

    • 通知设置:定义在发生自动缩放事件时应发送的通知,前提是符合某个自动缩放设置的配置文件的条件。A notification setting defines what notifications should occur when an autoscale event occurs based on satisfying the criteria of one of the autoscale setting’s profiles. 自动缩放可以将通知发送到一个或多个电子邮件地址,也可以对一个或多个 webhook 进行调用。Autoscale can notify one or more email addresses or make calls to one or more webhooks.

Azure 自动缩放设置、配置文件和规则结构

自动缩放 REST API 中提供了可配置字段和说明的完整列表。The full list of configurable fields and descriptions is available in the Autoscale REST API.

有关代码示例,请参阅For code examples, see

水平缩放和垂直缩放Horizontal vs vertical scaling

自动缩放仅以横向方式调整资源的规模,即只增加(“放”)或减少(“缩”)VM 实例的数目。Autoscale only scales horizontally, which is an increase ("out") or decrease ("in") in the number of VM instances. 横向缩放在使用云服务的情况下更为灵活,因为这样可以运行数千个处理负载的 VM。Horizontal is more flexible in a cloud situation as it allows you to run potentially thousands of VMs to handle load.

纵向缩放与此不同。In contrast, vertical scaling is different. 它保持 VM 数量不变,但会增强(“提高”)或削弱(“降低”)VM 的功能。It keeps the same number of VMs, but makes the VMs more ("up") or less ("down") powerful. 功能按内存、CPU 速度、磁盘空间等指标衡量。垂直缩放有更多的限制。Power is measured in memory, CPU speed, disk space, etc. Vertical scaling has more limitations. 具体取决于更大型硬件的可用性,此可用性会快速达到上限,并因区域而异。It's dependent on the availability of larger hardware, which quickly hits an upper limit and can vary by region. 纵向缩放通常还需要停止和重新启动 VM。Vertical scaling also usually requires a VM to stop and restart.

访问方法Methods of access

可以通过以下方式设置自动缩放:You can set up autoscale via

支持进行自动缩放的服务Supported services for autoscale

服务Service 架构和文档Schema & Docs
Web 应用Web Apps 缩放 Web 应用Scaling Web Apps
云服务Cloud Services 自动缩放云服务Autoscale a Cloud Service
虚拟机:经典Virtual Machines: Classic 缩放经典虚拟机可用性集Scaling Classic Virtual Machine Availability Sets
虚拟机:Windows 规模集Virtual Machines: Windows Scale Sets 缩放 Windows 中的虚拟机规模集Scaling virtual machine scale sets in Windows
虚拟机:Linux 规模集Virtual Machines: Linux Scale Sets 缩放 Linux 中的虚拟机规模集Scaling virtual machine scale sets in Linux
虚拟机:Windows 示例Virtual Machines: Windows Example 通过用于 VM 规模集的 Resource Manager 模板进行的高级自动缩放配置Advanced Autoscale configuration using Resource Manager templates for VM Scale Sets
API 管理服务API Management service 自动缩放 Azure API 管理实例Automatically scale an Azure API Management instance
Azure 数据资源管理器群集Azure Data Explorer Clusters 管理 Azure 数据资源管理器群集缩放以适应不断变化的需求Manage Azure Data Explorer clusters scaling to accommodate changing demand
Azure 应用服务Azure App Service 在 Azure 应用服务中纵向扩展应用Scale up an app in Azure App service

后续步骤Next steps

若要详细了解自动缩放,请使用前面列出的自动缩放演练,或参阅以下资源:To learn more about autoscale, use the Autoscale Walkthroughs listed previously or refer to the following resources: