Given the creation of CosmosDB using GraphAPI. A graph with ~ 4k vertices and ~ 10k edges, a similar query from GraphAPI and DocumentAPI to the same database shows significantly different runtimes. I tested the difference between the APIs using the following node application:
var Gremlin = require('gremlin');
var config = require("./config");
var documentdb = require('documentdb');
const docClient = new documentdb.DocumentClient(....);
const graphClient = Gremlin.createClient(....);
const start = new Date();
graphClient.execute('g.V("12345")', {}, (err, results) => {
const end = new Date();
if (err) {
return console.error(err);
}
console.log(`GraphDB API Results in: ${(end.getTime() - start.getTime()) / 1000}`);
});
var querySpec = {
query: 'SELECT * FROM c ' +
'WHERE c.id = "12345"',
};
const docStart = new Date();
docClient.queryDocuments("dbs/graphdb/colls/sn", querySpec).toArray((err, results) => {
const docEnd = new Date();
if (err) {
console.error(JSON.stringify(err, null, 2));
return;
}
console.log(`DocumentDB API Results in: ${(docEnd.getTime() - docStart.getTime()) / 1000}`)
});
The result of this code shows that the requested single document returns GraphAPI in ~ 1.8 seconds, where when the document returns from documentdb api after ~ 0.3 seconds.
Result of DocumentDB API:
[
{
"label": "company",
"id": "12345",
"parent": [
{
"_value": "54321",
"id": "de7c87f7-83db-43c2-8ddd-c5487dd5682e"
}
],
"name": [
{
"_value": "Acme Co",
"id": "b4316415-d5c3-4dcc-ac5f-64b1d8c8bd62"
}
],
"_rid": "KPk3APUeEgFcAAAAAAAAAA==",
"_self": "dbs/KPk3AA==/colls/KPk3APUeEgE=/docs/KPk3APUeEgFcAAAAAAAAAA==/",
"_etag": "\"0000df07-0000-0000-0000-5a2b23bd0000\"",
"_attachments": "attachments/",
"_ts": 1512776637
}
]
GraphDB API Result:
[
{
"id": "12345",
"label": "company",
"type": "vertex",
"properties": {
"parent": [
{
"id": "de7c87f7-83db-43c2-8ddd-c5487dd5682e",
"value": "54321"
}
],
"name": [
{
"id": "b4316415-d5c3-4dcc-ac5f-64b1d8c8bd62",
"value": "Acme Co"
}
]
}
}
]
All of these examples are taken from a fixed-size collection, where RU deployed up to 10,000.
- ? // ? , , Cosmos, , .
(gV(). hasLabel ('x'). out ('y'). hasLabel ('z')), 5 , , hasLabel ('x') count ~ 40. hasLabel ('x') ~ 1000, 15 . .
, . ?