【问题标题】:Understanding "x-ms-request-charge" and "x-ms-total-request-charge" in CosmosDB Gremlin API了解 CosmosDB Gremlin API 中的“x-ms-request-charge”和“x-ms-total-request-charge”
【发布时间】:2020-04-17 04:14:53
【问题描述】:

我正在使用 gremlin (version 3.4.6) 包来查询我的 Cosmos DB 帐户,以 Gremlin (Graph) API 为目标。代码相当简单:

const gremlin = require('gremlin');

const authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator(
`/dbs/<database-name>/colls/<container-name>`,
"<my-account-key>"
);
const client = new gremlin.driver.Client(
    "wss://<account-name>.gremlin.cosmosdb.azure.com:443/",
    {
        authenticator,
        traversalsource : "g",
        rejectUnauthorized : true,
        mimeType : "application/vnd.gremlin-v2.0+json"
    }
);

client.submit("g.V()")
.then((result) => {
    console.log(result);
})
.catch((error) => {
    console.log(error);
});

代码运行良好,我正在返回结果。结果对象有一个attributes 属性,看起来像这样:

{
    "x-ms-status-code": 200,
    "x-ms-request-charge": 0,
    "x-ms-total-request-charge": 123.85999999999989,
    "x-ms-server-time-ms": 0.0419,
    "x-ms-total-server-time-ms": 129.73709999999994,
    "x-ms-activity-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

如果您注意到,有两件事与请求费用有关(基本上我的查询有多贵):x-ms-request-chargex-ms-total-request-charge

对此我有三个问题:

  1. 两者有什么区别?
  2. 我注意到x-ms-request-charge 总是以0x-ms-total-request-charge 作为非零值出现。这是为什么?和
  3. 我应该使用哪个值来计算请求费用?我的猜测是使用x-ms-total-request-charge,因为它是一个非零值。

在我们讨论的过程中,如果有人能告诉我x-ms-server-time-msx-ms-total-server-time-ms 之间的区别,我将不胜感激。

【问题讨论】:

  • 调查这个。我们的Rest API 没有记录您所询问的内容。尽快回复您。
  • 感谢@MarkBrown。如果我需要更多信息,请告诉我。
  • 这似乎是 Gremlin 特有的。现在正在努力获取详细信息。谢谢。

标签: node.js azure azure-cosmosdb gremlin azure-cosmosdb-gremlinapi


【解决方案1】:

这些响应代码特定于我们的 Gremlin API,并记录在此处,Azure Cosmos DB Gremlin server response headers

对于单个请求,Gremlin 服务器可以发送带有多个部分响应消息的响应(大致相当于一个页面,但以流的形式返回,而不是像 SQL API 那样带有连续的多个请求/响应)。

  • x-ms-request-charge 是用于解决单个部分响应的 RU。
  • x-ms-total-request-charge 正在运行的总 RU 消耗到当前的部分响应。因此,当发送最终消息时,这将表示整个请求消耗的 RU 总数。

根据 Gremlin 客户端驱动程序的实现,每个部分响应可能会暴露给调用者,或者驱动程序将在内部累积所有响应并返回最终结果。鉴于后者,这促使我们添加 x-ms-total-request-charge,以便以这种方式实现的驱动程序仍然可以解决请求的总成本。

感谢您的提问,希望对您有所帮助。

【讨论】:

  • 感谢马克的回答!这很有帮助。我确实有一些后续问题,但我会在您链接的文档页面上打开一个 Github 问题。再次感谢。
猜你喜欢
  • 2018-09-04
  • 1970-01-01
  • 2017-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-10
  • 2017-05-27
相关资源
最近更新 更多