0

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

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-ms感激x-ms-total-server-time-ms

4

1 回答 1

1

These response codes are specific to our Gremlin API and are documented here, Azure Cosmos DB Gremlin server response headers.

For a single request, Gremlin server can send response with multiple partial response messages (loosely equivalent to a page, but returned as a stream instead of multiple request/responses with continuations as is done with SQL API).

  • x-ms-request-charge is the RUs consumed to resolve a single partial response.
  • x-ms-total-request-charge is running total RUs consumed up to the current partial response. So when the final message is sent, this will denote the total RUs consumed for the entire request.

Depending on the Gremlin client driver implementation, each partial responses may be exposed to the caller OR the driver will accumulate all responses internally and return a final result. Given the latter, this prompted us to add the x-ms-total-request-charge, so that drivers implemented this way could still resolve the total cost of the request.

Thanks for the question and hope this is helpful.

于 2020-04-16T20:14:53.793 回答