自动缩放 Azure API 管理实例Automatically scale an Azure API Management instance

Azure API 管理服务实例可以根据一组规则自动缩放。Azure API Management service instance can scale automatically based on a set of rules. 此行为可以通过 Azure Monitor 启用和配置,仅在 Azure API 管理服务的标准高级层中受支持。This behavior can be enabled and configured through Azure Monitor and is supported only in Standard and Premium tiers of the Azure API Management service.

本文逐步讲解配置自动缩放的过程,并建议自动缩放规则的最佳配置。The article walks through the process of configuring autoscale and suggests optimal configuration of autoscale rules.

先决条件Prerequisites

若要执行本文中的步骤,必须:To follow the steps from this article, you must:

可用性Availability

Important

此功能在 API 管理的“高级”、“标准”、“基本”和“开发人员”层中可用。This feature is available in the Premium, Standard, Basic and Developer tiers of API Management.

Azure API 管理自动缩放的限制Azure API Management autoscale limitations

在配置自动缩放行为之前,需要考虑到缩放存在的某些限制和造成的后果。Certain limitations and consequences of scaling decisions need to be considered before configuring autoscale behavior.

  • 只能为 Azure API 管理服务的标准高级层启用自动缩放。Autoscale can be enabled only for Standard and Premium tiers of Azure API Management service.
  • 定价层还指定了服务实例的最大单元数。Pricing tiers also specify the maximum number of units for a service instance.
  • 缩放过程至少需要 20 分钟。Scaling process will take at least 20 minutes.
  • 如果服务被另一操作锁定,则缩放请求将会失败并自动重试。If the service is locked by another operation, scaling request will fail and retry automatically.
  • 对于使用多区域部署的服务,只能缩放主要位置中的单元。In case of a service with multi-regional deployments, only units in the Primary location can be scaled. 不能缩放其他位置中的单元。Units in other locations can't be scaled.

为 Azure API 管理服务启用和配置自动缩放Enable and configure autoscale for Azure API Management service

遵循以下步骤为 Azure API 管理服务配置自动缩放:Follow the steps below to configure autoscale for an Azure API Management service:

  1. 在 Azure 门户中导航到“Monitor”实例。Navigate to Monitor instance in the Azure portal.

    Azure Monitor

  2. 在左侧菜单中选择“自动缩放”。Select Autoscale from the menu on the left.

    Azure Monitor - 自动缩放 - 资源

  3. 基于下拉菜单中的筛选器找到自己的 Azure API 管理服务。Locate your Azure API Management service based on the filters in dropdown menus.

  4. 选择所需的 Azure API 管理服务实例。Select the desired Azure API Management service instance.

  5. 在新打开的部分,单击“启用自动缩放”按钮。In the newly opened section, click the Enable autoscale button.

    Azure Monitor - 自动缩放 - 启用

  6. 在“规则”部分,单击“+ 添加规则”。In the Rules section, click + Add a rule.

    Azure Monitor - 自动缩放 - 添加规则

  7. 定义新的横向扩展规则。Define a new scale out rule.

    例如,当过去 30 分钟的平均容量指标超过 80% 时,横向扩展规则可以触发添加 Azure API 管理单元的操作。For example, a scale out rule could trigger an addition of an Azure API Management unit, when the average capacity metric over the last 30 minutes exceeds 80%. 下表提供了此类规则的配置。The table below provides configuration for such a rule.

    参数Parameter Value 注释Notes
    指标源Metric source 当前资源Current resource 基于当前的 Azure API 管理资源指标定义规则。Define the rule based on the current Azure API Management resource metrics.
    条件Criteria
    时间聚合Time aggregation 平均值Average
    指标名称Metric name 容量Capacity 容量指标是一个 Azure API 管理标准,用于反映 Azure API 管理实例的资源用量。Capacity metric is an Azure API Management metric reflecting usage of resources of an Azure API Management instance.
    时间粒度统计信息Time grain statistic 平均值Average
    运算符Operator 大于Greater than
    阈值Threshold 80%80% 平均容量指标的阈值。The threshold for the averaged capacity metric.
    持续时间(分钟)Duration (in minutes) 3030 要计算平均值的容量指标的时间跨度特定于使用模式。The timespan to average the capacity metric over is specific to usage patterns. 该时间段越长,做出的反应就越流畅 - 间歇性高峰对横向扩展决策的影响较小。The longer the time period is, the smoother the reaction will be - intermittent spikes will have less effect on the scale-out decision. 但是,它还会延迟横向扩展触发器。However, it will also delay the scale-out trigger.
    操作Action
    操作Operation 增加计数Increase count by
    实例计数Instance count 11 以 1 个单位为增量横向扩展 Azure API 管理实例。Scale out the Azure API Management instance by 1 unit.
    冷却(分钟)Cool down (minutes) 6060 横向扩展 Azure API 管理服务至少需要 20 分钟。在大多数情况下,60 分钟冷却期可以防止触发许多的横向扩展操作。It takes at least 20 minutes for the Azure API Management service to scale out. In most cases, the cool down period of 60 minutes prevents from triggering many scale-outs.
  8. 单击“添加”保存规则。Click Add to save the rule.

    Azure Monitor - 横向扩展规则

  9. 再次单击“+ 添加规则”。Click again on + Add a rule.

    这次需要定义横向缩减规则。This time, a scale in rule needs to be defined. 这可以确保在 API 用量减少时不会浪费资源。It will ensure resources are not being wasted, when the usage of APIs decreases.

  10. 定义新的横向缩减规则。Define a new scale in rule.

    例如,当过去 30 分钟的平均容量指标低于 35% 时,横向缩减规则可以触发删除 Azure API 管理单元的操作。For example, a scale in rule could trigger a removal of an Azure API Management unit, when the average capacity metric over the last 30 minutes has been lower than 35%. 下表提供了此类规则的配置。The table below provides configuration for such a rule.

    参数Parameter Value 注释Notes
    指标源Metric source 当前资源Current resource 基于当前的 Azure API 管理资源指标定义规则。Define the rule based on the current Azure API Management resource metrics.
    条件Criteria
    时间聚合Time aggregation 平均值Average
    指标名称Metric name 容量Capacity 横向扩展规则所用的相同指标。Same metric as the one used for the scale out rule.
    时间粒度统计信息Time grain statistic 平均值Average
    运算符Operator 小于Less than
    阈值Threshold 35%35% 与横向扩展规则类似,此值在很大程度取决于 Azure API 管理的使用模式。Similarly to the scale out rule, this value heavily depends on the usage patterns of the Azure API Management.
    持续时间(分钟)Duration (in minutes) 3030 横向扩展规则所用的相同值。Same value as the one used for the scale out rule.
    操作Action
    操作Operation 减少计数Decrease count by 与横向扩展规则使用的值相反。Opposite to what was used for the scale out rule.
    实例计数Instance count 11 横向扩展规则所用的相同值。Same value as the one used for the scale out rule.
    冷却(分钟)Cool down (minutes) 9090 横向缩减应该比横向扩展更保守,因此冷却期应该更长。Scale in should be more conservative than a scale out, so the cool down period should be longer.
  11. 单击“添加”保存规则。Click Add to save the rule.

    Azure Monitor - 横向缩减规则

  12. 设置 Azure API 管理单元的最大数目。Set the maximum number of Azure API Management units.

    Note

    Azure API 管理会限制实例可以横向扩展到单元数。Azure API Management has a limit of units an instance can scale out to. 此限制取决于服务层。The limit depends on a service tier.

    Azure Monitor - 横向缩减规则

  13. 单击“保存” 。Click Save. 现已配置自动缩放。Your autoscale has been configured.

后续步骤Next steps