Search code examples
azure.net-coreazure-cosmosdbazure-table-storageazure-cosmosdb-tables

How to avoid startup latency for Azure Table Storage/Cosmos DB Table API on .Net Core


Microsoft documentation here suggests to use await client.OpenAsync(); to avoid startup latency to Cosmos DB. This seems to be only applicable to SQL API. I try to use Table API and could not manage to do the same. My first request executes in 1500 ms and subsequent takes only 40, so that would be a very nice improvement.

I had tried both Microsoft.Azure.Cosmos.Table and Microsoft.WindowsAzure.Storage to connect, but did not find any way of doing that. The only thing I can think of is doing a "dummy" request that for sure does not return anything instead to achieve the same goal.

Is there any better way to initialize the connection?


Solution

  • A simple solution would be to query anything that you know exists.

    Any call using the client will initialise the connection and do the (approximately) 8 requests that CosmosDB needs.

    Reading the database account would be the simplest way to achieve this.