首页 > 解决方案 > 如何使用 Azure Cosmos DB 消耗超过保留数量的请求单元?

问题描述

我们为我们的各种集合保留了每秒不同数量的 RU。我正在尝试优化它以节省资金。对于来自 Cosmos 的每个响应,我们将请求费用属性记录到 Application Insights。我有一个分析查询返回每秒请求单位的平均数,一个返回最大值。

let start = datetime(2019-01-24 11:00:00);
let end = datetime(2019-01-24 21:00:00);
customMetrics
| where name == 'RequestCharge' and start < timestamp and timestamp < end
| project timestamp, value, Database=tostring(customDimensions['Database']), Collection=tostring(customDimensions['Collection'])
| make-series sum(value) default=0 on timestamp in range(start, end, 1s) by Database, Collection
| mvexpand sum_value to typeof(double), timestamp limit 36000
| summarize avg(sum_value) by Database, Collection
| order by Database asc, Collection asc
let start = datetime(2019-01-24 11:00:00);
let end = datetime(2019-01-24 21:00:00);
customMetrics
| where name == 'RequestCharge' and start <= timestamp and timestamp <= end
| project timestamp, value, Database=tostring(customDimensions['Database']), Collection=tostring(customDimensions['Collection'])
| summarize sum(value) by Database, Collection, bin(timestamp, 1s)
| summarize arg_max(sum_value, *) by Database, Collection 
| order by Database asc, Collection asc

平均值相当低,但在某些情况下最大值可能高得令人难以置信。一个极端的例子是一个预留 1,000,平均使用 15,59,最大使用 63,341 RUs/s 的集合。

我的问题是:这怎么可能?我的查询错了吗?节流不起作用吗?还是节流仅在比一秒更长的时间内起作用?我在 Azure Cosmos DB 概览仪表板上检查了请求限制(响应代码 429),但没有。

标签: azureazure-cosmosdb

解决方案


我必须自己回答。我发现了两个问题:

  1. Application Insights 记录不准确的时间戳。我添加了一个时间戳作为自定义维度,在特定的一分钟内,我在自定义时间戳中获得了不同的秒数,但对于其中许多来说,内置时间戳是一分钟后的一秒。这就是为什么我在请求费用中得到(错误的)峰值。
  2. 我们确实有节流。在门户中查看请求限制时,我必须选择一个特定的数据库。如果我尝试查看所有数据库的请求限制,看起来好像没有。

推荐阅读