限制 Resource Manager 请求数Throttling Resource Manager requests

本文介绍 Azure 资源管理器如何限制请求。This article describes how Azure Resource Manager throttles requests. 其中介绍了如何在达到限制之前跟踪剩余的请求数,以及在达到限制时如何采取应对措施。It shows you how to track the number of requests that remain before reaching the limit, and how to respond when you've reached the limit.

限制在两个级别发生。Throttling happens at two levels. Azure 资源管理器限制对订阅和租户的请求。Azure Resource Manager throttles requests for the subscription and tenant. 如果请求低于订阅和租户的限制,资源管理器会将该请求路由到资源提供程序。If the request is under the throttling limits for the subscription and tenant, Resource Manager routes the request to the resource provider. 资源提供程序应用针对该订阅和租户的操作专门指定的限制。The resource provider applies throttling limits that are tailored to its operations.

订阅和租户限制Subscription and tenant limits

每个订阅级别和租户级别的操作都会受到限制。Every subscription-level and tenant-level operation is subject to throttling limits. 订阅请求是需要传递订阅 ID 的请求,例如在订阅中检索资源组。Subscription requests are ones that involve passing your subscription ID, such as retrieving the resource groups in your subscription. 租户请求不包括订阅 ID,例如,检索有效的 Azure 位置。Tenant requests don't include your subscription ID, such as retrieving valid Azure locations.

下表显示了每小时的默认限制。The default throttling limits per hour are shown in the following table.

作用域Scope 操作Operations 限制Limit
订阅Subscription 读取reads 1200012000
订阅Subscription 删除deletes 1500015000
订阅Subscription 写入writes 12001200
租户Tenant 读取reads 1200012000
租户Tenant 写入writes 12001200

这些限制的范围是发出请求的安全主体(用户或应用程序)和订阅 ID 或租户 ID。These limits are scoped to the security principal (user or application) making the requests and the subscription ID or tenant ID. 如果请求来自多个安全主体,则对订阅或租户的限制大于每小时 12,000 个和每小时 1,200 个。If your requests come from more than one security principal, your limit across the subscription or tenant is greater than 12,000 and 1,200 per hour.

这些限制适用于每个 Azure 资源管理器实例。These limits apply to each Azure Resource Manager instance. 每个 Azure 区域中有多个实例,Azure 资源管理器将部署到所有 Azure 区域。There are multiple instances in every Azure region, and Azure Resource Manager is deployed to all Azure regions. 因此,实践中的限制要高于这些限制。So, in practice, the limits are higher than these limits. 来自用户的请求通常由不同的 Azure 资源管理器实例进行处理。The requests from a user are usually handled by different instances of Azure Resource Manager.

资源提供程序限制Resource provider limits

资源提供程序应用自身的限制。Resource providers apply their own throttling limits. 由于资源管理器按主体 ID 和资源管理器实例进行限制,因此资源提供程序收到的请求数可能会超过上一部分所述的默认限制。Because Resource Manager throttles by principal ID and by instance of Resource Manager, the resource provider might receive more requests than the default limits in the previous section.

本部分讨论某些广泛使用的资源提供程序的限制。This section discusses the throttling limits of some widely used resource providers.

存储限制Storage throttling

仅当使用 Azure 资源管理器对 Azure 存储执行管理操作时,以下限制才适用。The following limits apply only when you perform management operations by using Azure Resource Manager with Azure Storage.

资源Resource 默认限制Default limit
存储帐户管理操作数(读取)Storage account management operations (read) 每 5 分钟 800 次800 per 5 minutes
存储帐户管理操作数(写入)Storage account management operations (write) 每小时 200 次200 per hour
存储帐户管理操作数(列出)Storage account management operations (list) 每 5 分钟 100 次100 per 5 minutes

网络限制Network throttling

Microsoft.Network 资源提供程序应用以下限制:The Microsoft.Network resource provider applies the following throttle limits:

操作Operation 限制Limit
写入/删除 (PUT)write / delete (PUT) 每 5 分钟 1000 次1000 per 5 minutes
读取 (GET)read (GET) 每 5 分钟 10000 次10000 per 5 minutes

计算限制Compute throttling

有关计算操作的限制的信息,请参阅排查 API 限制错误 - 计算For information about throttling limits for compute operations, see Troubleshooting API throttling errors - Compute.

若要检查虚拟机规模集中的虚拟机实例,请使用虚拟机规模集操作For checking virtual machine instances within a virtual machine scale set, use the Virtual Machine Scale Sets operations. 例如,使用虚拟机规模集 VM - 列出和相应的参数来检查虚拟机实例的电源状态。For example, use the Virtual Machine Scale Set VMs - List with parameters to check the power state of virtual machine instances. 此 API 可减少请求数。This API reduces the number of requests.

Azure Resource Graph 限制Azure Resource Graph throttling

Azure Resource Graph 会限制对其操作发出的请求数。Azure Resource Graph limits the number of requests to its operations. 本文所述的用于确定剩余请求数以及在达到限制时如何采取应对措施的步骤同样适用于 Resource Graph。The steps in this article to determine the remaining requests and how to respond when the limit is reached also apply to Resource Graph. 但是,Resource Graph 设置了自身的限制和重置速率。However, Resource Graph sets its own limit and reset rate. 有关详细信息,请参阅 Azure Resource Graph 中的限制For more information, see Throttle in Azure Resource Graph.

请求增加Request increase

有时可以提高限制。Sometimes, throttle limits can be increased. 若要确定是否可以提高你的方案限制,请创建支持请求。To see if the throttling limits for your scenario can be increased, create a support request. 我们将详细评估你的调用模式。The details of your calling pattern will be evaluated.

错误代码Error code

达到限制时,会收到 HTTP 状态代码“429 请求过多” 。When you reach the limit, you receive the HTTP status code 429 Too many requests. 响应包含 Retry-After 值,该值指定在发送下一个请求之前应用程序应该等待(或休眠)的秒数。The response includes a Retry-After value, which specifies the number of seconds your application should wait (or sleep) before sending the next request. 如果在尚未达到重试时间值的情况下发送请求,该请求不会得到处理,并会返回一个新的重试时间值。If you send a request before the retry value has elapsed, your request isn't processed and a new retry value is returned.

等待指定的时间后,还可以关闭再重新打开与 Azure 的连接。After waiting for specified time, you can also close and reopen your connection to Azure. 通过重置连接,可以连接到 Azure 资源管理器的其他实例。By resetting the connection, you may connect to a different instance of Azure Resource Manager.

如果使用的是 Azure SDK,该 SDK 可能会采用自动重试配置。If you're using an Azure SDK, the SDK may have an auto retry configuration. 有关详细信息,请参阅 Azure 服务的重试指南For more information, see Retry guidance for Azure services.

某些资源提供程序返回 429 来报告暂时性问题。Some resource providers return 429 to report a temporary problem. 该问题可能是一种过载状态,它不是由你的请求直接造成的。The problem could be an overload condition that isn't directly caused by your request. 或者,它可能表示目标资源或依赖资源的状态相关的暂时性错误。Or, it could represent a temporary error about the state of the target resource or dependent resource. 例如,当目标资源被另一个操作锁定时,网络资源提供程序将返回 429 和 RetryableErrorDueToAnotherOperation 错误代码。For example, the network resource provider returns 429 with the RetryableErrorDueToAnotherOperation error code when the target resource is locked by another operation. 若要确定错误是由限制还是暂时性的状况造成,请查看响应中的错误详细信息。To determine if the error comes from throttling or a temporary condition, view the error details in the response.

剩余请求数Remaining requests

可以通过检查响应标头确定剩余请求数。You can determine the number of remaining requests by examining response headers. 读取请求在标头中返回一个值,表示剩余读取请求的数目。Read requests return a value in the header for the number of remaining read requests. 写入请求包含的值表示剩余写入请求的数目。Write requests include a value for the number of remaining write requests. 下表说明了各种响应标头,用户可以检查其中是否存在这些值:The following table describes the response headers you can examine for those values:

响应标头Response header 说明Description
x-ms-ratelimit-remaining-subscription-readsx-ms-ratelimit-remaining-subscription-reads 划归到订阅的剩余读取数。Subscription scoped reads remaining. 执行读取操作时返回此值。This value is returned on read operations.
x-ms-ratelimit-remaining-subscription-writesx-ms-ratelimit-remaining-subscription-writes 划归到订阅的剩余写入数。Subscription scoped writes remaining. 执行写入操作时返回此值。This value is returned on write operations.
x-ms-ratelimit-remaining-tenant-readsx-ms-ratelimit-remaining-tenant-reads 租户范围的剩余读取数Tenant scoped reads remaining
x-ms-ratelimit-remaining-tenant-writesx-ms-ratelimit-remaining-tenant-writes 租户范围的剩余写入数Tenant scoped writes remaining
x-ms-ratelimit-remaining-subscription-resource-requestsx-ms-ratelimit-remaining-subscription-resource-requests 划归到订阅的剩余资源类型请求数。Subscription scoped resource type requests remaining.

仅当服务重写了默认限制时,才返回此标头值。This header value is only returned if a service has overridden the default limit. Resource Manager 将累加此值而不是订阅读取/写入数。Resource Manager adds this value instead of the subscription reads or writes.
x-ms-ratelimit-remaining-subscription-resource-entities-readx-ms-ratelimit-remaining-subscription-resource-entities-read 划归到订阅的剩余资源类型集合请求数。Subscription scoped resource type collection requests remaining.

仅当服务重写了默认限制时,才返回此标头值。This header value is only returned if a service has overridden the default limit. 此值提供剩余集合请求数(列出资源)。This value provides the number of remaining collection requests (list resources).
x-ms-ratelimit-remaining-tenant-resource-requestsx-ms-ratelimit-remaining-tenant-resource-requests 划归到租户的剩余资源类型请求数。Tenant scoped resource type requests remaining.

仅当服务重写了默认限制时,才为租户级别的请求添加此标头。This header is only added for requests at tenant level, and only if a service has overridden the default limit. Resource Manager 将累加此值而不是租户读取/写入数。Resource Manager adds this value instead of the tenant reads or writes.
x-ms-ratelimit-remaining-tenant-resource-entities-readx-ms-ratelimit-remaining-tenant-resource-entities-read 划归到租户的剩余资源类型集合请求数。Tenant scoped resource type collection requests remaining.

仅当服务重写了默认限制时,才为租户级别的请求添加此标头。This header is only added for requests at tenant level, and only if a service has overridden the default limit.

资源提供程序还可以返回包含剩余请求数相关信息的响应标头。The resource provider can also return response headers with information about remaining requests. 有关“计算”资源提供程序返回的响应标头的信息,请参阅调用速率参考性响应标头For information about response headers returned by the Compute resource provider, see Call rate informational response headers.

检索标头值Retrieving the header values

检索代码或脚本中的这些标头值与检索任何标头值没有什么不同。Retrieving these header values in your code or script is no different than retrieving any header value.

例如,在 C# 中,可使用以下代码从名为 responseHttpWebResponse 对象中检索标头值:For example, in C#, you retrieve the header value from an HttpWebResponse object named response with the following code:

response.Headers.GetValues("x-ms-ratelimit-remaining-subscription-reads").GetValue(0)

PowerShell中,可以通过 Invoke-WebRequest 操作检索标头值。In PowerShell, you retrieve the header value from an Invoke-WebRequest operation.

$r = Invoke-WebRequest -Uri https://management.chinacloudapi.cn/subscriptions/{guid}/resourcegroups?api-version=2016-09-01 -Method GET -Headers $authHeaders
$r.Headers["x-ms-ratelimit-remaining-subscription-reads"]

有关完整的 PowerShell 示例,请参阅查看订阅的资源管理器限制For a complete PowerShell example, see Check Resource Manager Limits for a Subscription.

若要查看剩余请求数以进行调试,可在 PowerShell cmdlet 中提供 -Debug 参数。If you want to see the remaining requests for debugging, you can provide the -Debug parameter on your PowerShell cmdlet.

Get-AzResourceGroup -Debug

这会返回许多值,包括以下响应值:Which returns many values, including the following response value:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
x-ms-ratelimit-remaining-subscription-reads: 11999

若要获取写入限制,请使用写入操作:To get write limits, use a write operation:

New-AzResourceGroup -Name myresourcegroup -Location chinanorth -Debug

这会返回许多值,包括以下值:Which returns many values, including the following values:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
Created

Headers:
Pragma                        : no-cache
x-ms-ratelimit-remaining-subscription-writes: 1199

Azure CLI中,可以使用更详细的选项检索标头值。In Azure CLI, you retrieve the header value by using the more verbose option.

az group list --verbose --debug

这会返回许多值,包括以下值:Which returns many values, including the following values:

msrest.http_logger : Response status: 200
msrest.http_logger : Response headers:
msrest.http_logger :     'Cache-Control': 'no-cache'
msrest.http_logger :     'Pragma': 'no-cache'
msrest.http_logger :     'Content-Type': 'application/json; charset=utf-8'
msrest.http_logger :     'Content-Encoding': 'gzip'
msrest.http_logger :     'Expires': '-1'
msrest.http_logger :     'Vary': 'Accept-Encoding'
msrest.http_logger :     'x-ms-ratelimit-remaining-subscription-reads': '11998'

若要获取写入限制,请使用写入操作:To get write limits, use a write operation:

az group create -n myresourcegroup --location chinanorth --verbose --debug

这会返回许多值,包括以下值:Which returns many values, including the following values:

msrest.http_logger : Response status: 201
msrest.http_logger : Response headers:
msrest.http_logger :     'Cache-Control': 'no-cache'
msrest.http_logger :     'Pragma': 'no-cache'
msrest.http_logger :     'Content-Length': '163'
msrest.http_logger :     'Content-Type': 'application/json; charset=utf-8'
msrest.http_logger :     'Expires': '-1'
msrest.http_logger :     'x-ms-ratelimit-remaining-subscription-writes': '1199'

后续步骤Next steps