簡體   English   中英

如何通過 ASP.NET Core 向 Cosmos DB 插入多個?

[英]How to insert many to Cosmos DB by ASP.NET Core?

有什么方法可以以最快的方式在具有 ASP.NET 核心的 Cosmos Db 中插入 +100 萬條記錄?

最近的方法是使用 .NET SDK v3 中的批量支持。 完整教程在這里:

https://learn.microsoft.com/en-us/azure/cosmos-db/tutorial-sql-api-do.net-bulk-import

您至少需要暫時增加數據庫的吞吐量,以實現您想要的攝取速度。

Cosmos DB SDK 允許通過 Do.net 庫的 AllowBulkExecution 選項使用批量executor器進行批量插入

// Set retry options high during initialization (default values).
client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 30;
client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 9;

IBulkExecutor bulkExecutor = new BulkExecutor(client, dataCollection);
await bulkExecutor.InitializeAsync();

// Set retries to 0 to pass complete control to bulk executor.
client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0;
client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM