Azure API 管理实例的容量Capacity of an Azure API Management instance

容量是最重要的单一 Azure Monitor 指标,在是否扩展 API 管理实例以容纳更多负载方面,它可以帮助做出明智的决策。Capacity is the single, most important Azure Monitor metric for making informed decisions whether to scale an API Management instance to accommodate more load. 容量的构造比较复杂,并且会施加特定的行为。Its construction is complex and imposes certain behavior.

本文介绍容量的定义及其行为。This article explains what the capacity is and how it behaves. 其中介绍了如何在 Azure 门户中访问容量指标,并建议何时应考虑扩展或升级 API 管理实例。It shows how to access capacity metrics in the Azure portal and suggests when to consider scaling or upgrading your API Management instance.

先决条件Prerequisites

若要遵循本文中的步骤,必须准备好:To follow the steps from this article, you must have:

可用性Availability

Important

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

什么是容量What is capacity

容量指标

容量是 APIM 实例中负载的指标。Capacity is an indicator of load on an APIM instance. 它反映资源用量(CPU、内存)和网络队列的长度。It reflects resources usage (CPU, memory) and network queue lengths. CPU 和内存用量反映以下对象的资源消耗量:CPU and memory usage reveals resources consumption by:

  • APIM 服务,例如管理操作或请求处理,可能包括转发请求或运行策略APIM services, such as management actions or request processing, which can include forwarding requests or running a policy
  • 选定的操作系统进程,包括在新连接上造成 SSL 握手开销的进程。selected operating system processes, including processes that involve cost of SSL handshakes on new connections.

容量是 API 管理实例的每个单元中容量自有值的平均值。Total capacity is an average of its own values from every unit of an API Management instance.

容量指标行为Capacity metric behavior

由于这种构造,在现实中,容量可能受到多种可变因素的影响,例如:Because of its construction, in real life capacity can be impacted by many variables, for example:

  • 连接模式(是根据请求创建新连接,还是重复使用现有连接)connection patterns (new connection on a request vs reusing the existing connection)
  • 请求和响应的大小size of a request and response
  • 在每个 API 中配置的策略数,或发送请求的客户端数。policies configured on each API or number of clients sending requests.

请求中的操作越复杂,容量消耗就越高。The more complex operations on the requests are, the higher the capacity consumption will be. 例如,复杂转换策略消耗的 CPU 比简单的请求转发要高得多。For example, complex transformation policies consume much more CPU than a simple request forwarding. 后端服务响应速度较慢也会增大消耗量。Slow backend service responses will increase it too.

Important

容量不是所处理请求数量的直接度量值。Capacity is not a direct measure of the number of requests being processed.

容量指标高峰

容量还可能会出现间歇性的高峰或大于零,即使未处理任何请求。Capacity can also spike intermittently or be greater than zero even if there are no requests being processed. 之所以发生这种情况,是因为存在系统或平台特定的操作。在决定是否缩放实例时,不应考虑这些因素。It happens because of system- or platform-specific actions and should not be taken into consideration when deciding whether to scale an instance.

使用 Azure 门户检查容量Use the Azure Portal to examine capacity

容量指标

  1. Azure 门户中导航到自己的 APIM 实例。Navigate to your APIM instance in the Azure portal.

  2. 选择“指标(预览)”。Select Metrics (preview).

  3. 在紫色部分,从可用指标中选择“容量”,并保留默认的“平均值”聚合。From the purple section, select Capacity metric from available metrics and leave the default Avg aggregation.

    Tip

    为避免解释错误,容量指标始终按位置分解。You should always look at a capacity metric breakdown per location to avoid wrong interpretations.

  4. 在绿色部分选择“位置”,以便按维度拆分指标。From the green section, select Location for splitting the metric by dimension.

  5. 从该部分的顶部栏中选择所需的时间范围。Pick a desired timeframe from the top bar of the section.

    可以设置指标警报,以便在发生意外的情况时收到通知。You can set a metric alert to let you know when something unexpected is happening. 例如,当 APIM 实例超出预期峰值容量有 20 分钟以上时收到通知。For example, get notifications when your APIM instance has been exceeding its expected peak capacity for over 20 minutes.

    Tip

    可以配置警报,以便在服务容量不足时知道这种状况;或者使用 Azure Monitor 自动缩放功能自动添加 Azure API 管理单元。You can configure alerts to let you know when your service is running low on capacity or use Azure Monitor autoscaling functionality to automatically add an Azure API Management unit. 缩放操作可能需要大约 30 分钟,因此请相应地安排规则。Scaling operation can take around 30 minutes, so you should plan your rules accordingly.
    只允许缩放主要位置。Only scaling the master location is allowed.

使用容量做出缩放决策Use capacity for scaling decisions

在是否扩展 API 管理实例以容纳更多负载方面,容量指标可以帮助做出决策。Capacity is the metric for making decisions whether to scale an API Management instance to accommodate more load. 请考虑:Consider:

  • 查看长期趋势和平均值。Looking at a long-term trend and average.
  • 忽略往往与负载提高无关的突发高峰(请参阅“容量指标行为”部分中的说明)。Ignoring sudden spikes that are most likely not related to any increase in load (see "Capacity metric behavior" section for explanation).
  • 容量值长时间(例如 30 分钟)超过 60% 或 70% 时,请升级或扩展实例。Upgrading or scaling your instance, when capacity's value exceeds 60% or 70% for a longer period of time (for example 30 minutes). 不同的值可能更适合服务或方案。Different values may work better for your service or scenario.

Tip

如果能够事先估算流量,请在预期的工作负荷上测试 APIM 实例。If you are able to estimate your traffic beforehand, test your APIM instance on workloads you expect. 可在租户中逐渐增大请求负载,并监视哪个容量指标值对应于峰值负载。You can increase the request load on your tenant gradually and monitor what value of the capacity metric corresponds to your peak load. 遵循上一部分中的步骤,使用 Azure 门户了解在任意给定时间使用的容量。Follow the steps from the previous section to use Azure portal to understand how much capacity is used at any given time.

后续步骤Next steps

如何扩展或升级 Azure API 管理服务实例How to scale or upgrade an Azure API Management service instance