I am testing CosmosDb. I am finding the initial connection usually takes many seconds.I have written a small .net core 2.2 Console App to demonstrate the problem.
static async System.Threading.Tasks.Task Main(string[] args)
{
Console.WriteLine("Hello World!");
string url = "https://docdb.documents.azure.com:443/";
string key = "myKey";
DocumentClient docClient = new DocumentClient(new Uri(url), key);
Stopwatch sw = new Stopwatch();
while (true)
{
sw.Start();
var res = await docClient.ReadDocumentAsync(UriFactory.CreateDocumentUri("ct", "ops", "xxx"),
new RequestOptions { PartitionKey = new Microsoft.Azure.Documents.PartitionKey("test") });
sw.Stop();
Console.WriteLine($"Query took {sw.ElapsedMilliseconds}ms");
sw.Reset();
await Task.Delay(1000);
}
}
Here are my typical results:
Hello World!
Query took 48530ms
Query took 36ms
Query took 26ms
Query took 15ms
The first request takes 48 secs! i tried ammending the docClient construction to:
DocumentClient docClient = new DocumentClient(new Uri(url), key,new
ConnectionPolicy {ConnectionMode = ConnectionMode.Direct,ConnectionProtocol
= Protocol.Tcp });
To see if it was better some typical results:
Hello World!
Query took 20536ms
Query took 104ms
Query took 37ms
Query took 71ms
Query took 13ms
Query took 88ms
Query took 14ms
Still 20 secs on first query.
My database is
130Mb
Avg Throughput /s* 3.58 RU/s
and I have
400 RU's
is there anything I can do to alleviate the delay in the first connection?
My Document on Cosmosdb is :
{
"id": "xxx",
"fid": "test",
"_rid": "VX8TAPKGDqNeWwEAAAAAAA==",
"_self": "dbs/VX8TAA==/colls/VX8TAPKGDqM=/docs/VX8TAPKGDqNeWwEAAAAAAA==/",
"_etag": "\"0000d4a2-0000-1100-0000-5ce801ef0000\"",
"_attachments": "attachments/",
"_ts": 1558708719
}