您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

防止 Azure Cosmos DB API for MongoDB 操作的速率限制错误Prevent rate-limiting errors for Azure Cosmos DB API for MongoDB operations

适用于: Azure Cosmos DB API for MongoDB

如果 Azure Cosmos DB API for MongoDB 操作超出集合的吞吐量限制 (RU),则可能失败,出现速率限制 (16500/429) 错误。Azure Cosmos DB API for MongoDB operations may fail with rate-limiting (16500/429) errors if they exceed a collection's throughput limit (RUs).

可以启用服务器端重试 (SSR) 功能,并让服务器自动重试这些操作。You can enable the Server Side Retry (SSR) feature and let the server retry these operations automatically. 短暂延迟后,你的帐户中的所有集合的请求会重试。The requests are retried after a short delay for all collections in your account. 此功能是处理客户端应用程序中的速率限制错误的便捷替代方法。This feature is a convenient alternative to handling rate-limiting errors in the client application.

使用 Azure 门户Use the Azure portal

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 导航到你的 Azure Cosmos DB API for MongoDB 帐户。Navigate to your Azure Cosmos DB API for MongoDB account.

  3. 转到“设置”部分下面的“功能”窗格 。Go to the Features pane underneath the Settings section.

  4. 选择“服务器端重试”。Select Server Side Retry.

  5. 单击“启用”为帐户中的所有集合启用此功能。Click Enable to enable this feature for all collections in your account.

适用于 Azure Cosmos DB API for MongoDB 的服务器端重试功能的屏幕截图

使用 Azure CLIUse the Azure CLI

  1. 检查是否已为你的帐户启用了 SSR:Check if SSR is already enabled for your account:
az cosmosdb show --name accountname --resource-group resourcegroupname
  1. 为数据库帐户中的所有集合启用 SSR。Enable SSR for all collections in your database account. 此更改生效可能需要长达 15 分钟的时间。It may take up to 15min for this change to take effect.
az cosmosdb update --name accountname --resource-group resourcegroupname --capabilities EnableMongo DisableRateLimitingResponses

以下命令会通过从功能列表中删除“DisableRateLimitingResponses”,对数据库帐户中的所有集合禁用 SSR。The following command will Disable SSR for all collections in your database account by removing "DisableRateLimitingResponses" from the capabilities list. 此更改生效可能需要长达 15 分钟的时间。It may take up to 15min for this change to take effect.

az cosmosdb update --name accountname --resource-group resourcegroupname --capabilities EnableMongo

常见问题Frequently Asked Questions

  • 如何重试请求?How are requests retried?
    • 连续(一次又一次)重试请求,直到出现 60 秒超时为止。Requests are retried continuously (over and over again) until a 60-second timeout is reached. 如果超时,则客户端会收到 ExceededTimeLimit 异常 (50)If the timeout is reached, the client will receive an ExceededTimeLimit exception (50).
  • 如何监视 SSR 的效果?How can I monitor the effects of SSR?
    • 可以在“Cosmos DB 指标”窗格中查看服务器端重试的速率限制错误 (429)。You can view the rate limiting errors (429s) that are retried server-side in the Cosmos DB Metrics pane. 请记住,启用 SSR 后,这些错误不会传递给客户端,因为它们是在服务器端处理和重试的。Keep in mind that these errors don't go to the client when SSR is enabled, since they are handled and retried server-side.
    • 可以在 Cosmos DB 资源日志中搜索包含“estimatedDelayFromRateLimitingInMilliseconds”的日志条目。You can search for log entries containing "estimatedDelayFromRateLimitingInMilliseconds" in your Cosmos DB resource logs.
  • SSR 是否会影响我的一致性级别?Will SSR affect my consistency level?
    • SSR 不会影响请求的一致性。SSR does not affect a request's consistency. 如果请求受到速率限制(出现 429 错误),则会在服务器端重试。Requests are retried server-side if they are rate limited (with a 429 error).
  • SSR 是否影响客户端可能收到的任何类型的错误?Does SSR affect any type of error that my client might receive?
    • 否。由于是在服务器端重试,SSR 只会影响速率限制错误 (429)。No, SSR only affects rate limiting errors (429s) by retrying them server-side. 有了此功能,就不必在客户端应用程序中处理速率限制错误。This feature prevents you from having to handle rate-limiting errors in the client application. 所有其他错误都会传递到客户端。All other errors will go to the client.

后续步骤Next steps

若要了解有关排除常见错误的更多信息,请参阅此文:To learn more about troubleshooting common errors, see this article: