2 years ago
#73299
Saqib
Writing to Cosmos DB very slow (using .Net SDK)
I am writing a console app (eventually to be an Azure Function) to retrieve some data, and write it to a container in Cosmos DB (currently using SQL version, but could use table storage as instead).
Making 10 million calls to Upsert, as in the below code, takes about 20 hours! Any recommendations to improve the speed significantly?
static async Task AddToDatabase(List<Product> products)
{
var client = new CosmosClient(connectionString, new CosmosClientOptions { AllowBulkExecution = true, EnableContentResponseOnWrite = false, SerializerOptions = new CosmosSerializationOptions { PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase } });
var container = client.GetContainer(databaseName, containerName);
var tasks = products.Select(p => container.UpsertItemAsync(p, new PartitionKey(p.Barcode)).ContinueWith(t => UpdateProgress()));
await Task.WhenAll(tasks);
}
Appreciate any pointers.
c#
azure
azure-cosmosdb
0 Answers
Your Answer