You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/nosql/bulk-executor-dotnet.md
+23-22Lines changed: 23 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,16 +7,17 @@ ms.service: cosmos-db
7
7
ms.subservice: nosql
8
8
ms.devlang: csharp
9
9
ms.topic: how-to
10
-
ms.date: 05/02/2020
10
+
ms.date: 03/14/2023
11
11
ms.reviewer: mjbrown
12
12
ms.custom: devx-track-csharp, ignite-2022
13
13
---
14
14
15
15
# Use the bulk executor .NET library to perform bulk operations in Azure Cosmos DB
16
+
16
17
[!INCLUDE[NoSQL](../includes/appliesto-nosql.md)]
17
18
18
19
> [!NOTE]
19
-
> This bulk executor library described in this article is maintained for applications using the .NET SDK 2.x version. For new applications, you can use the **bulk support** that is directly available with the [.NET SDK version 3.x](tutorial-dotnet-bulk-import.md) and it does not require any external library.
20
+
> This bulk executor library described in this article is maintained for applications using the .NET SDK 2.x version. For new applications, you can use the **bulk support** that is directly available with the [.NET SDK version 3.x](tutorial-dotnet-bulk-import.md) and it does not require any external library.
20
21
21
22
> If you are currently using the bulk executor library and planning to migrate to bulk support on the newer SDK, use the steps in the [Migration guide](how-to-migrate-from-bulk-executor-library.md) to migrate your application.
22
23
@@ -48,9 +49,9 @@ The "BulkImportSample" application generates random documents and bulk imports t
48
49
49
50
## <aid="bulk-import-data-to-an-azure-cosmos-account"></a>Bulk import data to an Azure Cosmos DB account
50
51
51
-
1. Navigate to the "BulkImportSample" folder and open the "BulkImportSample.sln" file.
52
+
1. Navigate to the "BulkImportSample" folder and open the "BulkImportSample.sln" file.
52
53
53
-
2. The Azure Cosmos DB's connection strings are retrieved from the App.config file as shown in the following code:
54
+
1. The Azure Cosmos DB's connection strings are retrieved from the App.config file as shown in the following code:
@@ -62,7 +63,7 @@ The "BulkImportSample" application generates random documents and bulk imports t
62
63
63
64
The bulk importer creates a new database and a container with the database name, container name, and the throughput values specified in the App.config file.
64
65
65
-
3. Next the DocumentClient object is initialized with Direct TCP connection mode:
66
+
1. Next the DocumentClient object is initialized with Direct TCP connection mode:
5. The application invokes the BulkImportAsync API. The .NET library provides two overloads of the bulk import API - one that accepts a list of serialized JSON documents and the other that accepts a list of deserialized POCO documents. To learn more about the definitions of each of these overloaded methods, refer to the [API documentation](/dotnet/api/microsoft.azure.cosmosdb.bulkexecutor.bulkexecutor.bulkimportasync).
93
+
1. The application invokes the BulkImportAsync API. The .NET library provides two overloads of the bulk import API - one that accepts a list of serialized JSON documents and the other that accepts a list of deserialized POCO documents. To learn more about the definitions of each of these overloaded methods, refer to the [API documentation](/dotnet/api/microsoft.azure.cosmosdb.bulkexecutor.bulkexecutor.bulkimportasync).
@@ -101,8 +102,8 @@ The "BulkImportSample" application generates random documents and bulk imports t
101
102
cancellationToken: token);
102
103
```
103
104
**BulkImportAsync method accepts the following parameters:**
104
-
105
-
|**Parameter**|**Description**|
105
+
106
+
|**Parameter**|**Description**|
106
107
|---------|---------|
107
108
|enableUpsert | A flag to enable upsert operations on the documents. If a document with the given ID already exists, it's updated. By default, it's set to false. |
108
109
|disableAutomaticIdGeneration | A flag to disable automatic generation of ID. By default, it's set to true. |
@@ -113,7 +114,7 @@ The "BulkImportSample" application generates random documents and bulk imports t
113
114
**Bulk import response object definition**
114
115
The result of the bulk import API call contains the following attributes:
115
116
116
-
|**Parameter**|**Description**|
117
+
|**Parameter**|**Description**|
117
118
|---------|---------|
118
119
|NumberOfDocumentsImported (long) | The total number of documents that were successfully imported out of the total documents supplied to the bulk import API call. |
119
120
|TotalRequestUnitsConsumed (double) | The total request units (RU) consumed by the bulk import API call. |
@@ -124,9 +125,9 @@ The "BulkImportSample" application generates random documents and bulk imports t
124
125
125
126
You can update existing documents by using the BulkUpdateAsync API. In this example, you'll set the `Name` field to a new value and remove the `Description` field from the existing documents. For the full set of supported update operations, refer to the [API documentation](/dotnet/api/microsoft.azure.cosmosdb.bulkexecutor.bulkupdate).
126
127
127
-
1. Navigate to the "BulkUpdateSample" folder and open the "BulkUpdateSample.sln" file.
128
+
1. Navigate to the "BulkUpdateSample" folder and open the "BulkUpdateSample.sln" file.
128
129
129
-
2. Define the update items along with the corresponding field update operations. In this example, you'll use `SetUpdateOperation` to update the `Name` field and `UnsetUpdateOperation` to remove the `Description` field from all the documents. You can also perform other operations like increment a document field by a specific value, push specific values into an array field, or remove a specific value from an array field. To learn about different methods provided by the bulk update API, refer to the [API documentation](/dotnet/api/microsoft.azure.cosmosdb.bulkexecutor.bulkupdate).
130
+
1. Define the update items along with the corresponding field update operations. In this example, you'll use `SetUpdateOperation` to update the `Name` field and `UnsetUpdateOperation` to remove the `Description` field from all the documents. You can also perform other operations like increment a document field by a specific value, push specific values into an array field, or remove a specific value from an array field. To learn about different methods provided by the bulk update API, refer to the [API documentation](/dotnet/api/microsoft.azure.cosmosdb.bulkexecutor.bulkupdate).
@@ -143,7 +144,7 @@ You can update existing documents by using the BulkUpdateAsync API. In this exam
143
144
}
144
145
```
145
146
146
-
3. The application invokes the BulkUpdateAsync API. To learn about the definition of the BulkUpdateAsync method, refer to the [API documentation](/dotnet/api/microsoft.azure.cosmosdb.bulkexecutor.ibulkexecutor.bulkupdateasync).
147
+
1. The application invokes the BulkUpdateAsync API. To learn about the definition of the BulkUpdateAsync method, refer to the [API documentation](/dotnet/api/microsoft.azure.cosmosdb.bulkexecutor.ibulkexecutor.bulkupdateasync).
@@ -154,7 +155,7 @@ You can update existing documents by using the BulkUpdateAsync API. In this exam
154
155
```
155
156
**BulkUpdateAsync method accepts the following parameters:**
156
157
157
-
|**Parameter**|**Description**|
158
+
|**Parameter**|**Description**|
158
159
|---------|---------|
159
160
|maxConcurrencyPerPartitionKeyRange | The maximum degree of concurrency per partition key range, setting this parameter to null will make the library to use the default value(20). |
160
161
|maxInMemorySortingBatchSize | The maximum number of update items pulled from the update items enumerator passed to the API call in each stage. For the in-memory sorting phase that happens before bulk updating, setting this parameter to null will cause the library to use the default minimum value(updateItems.count, 1000000). |
@@ -163,23 +164,23 @@ You can update existing documents by using the BulkUpdateAsync API. In this exam
163
164
**Bulk update response object definition**
164
165
The result of the bulk update API call contains the following attributes:
165
166
166
-
|**Parameter**|**Description**|
167
+
|**Parameter**|**Description**|
167
168
|---------|---------|
168
169
|NumberOfDocumentsUpdated (long) | The number of documents that were successfully updated out of the total documents supplied to the bulk update API call. |
169
170
|TotalRequestUnitsConsumed (double) | The total request units (RUs) consumed by the bulk update API call. |
170
171
|TotalTimeTaken (TimeSpan) | The total time taken by the bulk update API call to complete the execution. |
171
-
172
-
## Performance tips
172
+
173
+
## Performance tips
173
174
174
175
Consider the following points for better performance when using the bulk executor library:
175
176
176
-
* For best performance, run your application from an Azure virtual machine that is in the same region as your Azure Cosmos DB account's write region.
177
+
* For best performance, run your application from an Azure virtual machine that is in the same region as your Azure Cosmos DB account's write region.
177
178
178
-
* It's recommended that you instantiate a single `BulkExecutor` object for the whole application within a single virtual machine that corresponds to a specific Azure Cosmos DB container.
179
+
* It's recommended that you instantiate a single `BulkExecutor` object for the whole application within a single virtual machine that corresponds to a specific Azure Cosmos DB container.
179
180
180
-
* A single bulk operation API execution consumes a large chunk of the client machine's CPU and network IO (This happens by spawning multiple tasks internally). Avoid spawning multiple concurrent tasks within your application process that execute bulk operation API calls. If a single bulk operation API call that is running on a single virtual machine is unable to consume the entire container's throughput (if your container's throughput > 1 million RU/s), it's preferred to create separate virtual machines to concurrently execute the bulk operation API calls.
181
+
* A single bulk operation API execution consumes a large chunk of the client machine's CPU and network IO (This happens by spawning multiple tasks internally). Avoid spawning multiple concurrent tasks within your application process that execute bulk operation API calls. If a single bulk operation API call that is running on a single virtual machine is unable to consume the entire container's throughput (if your container's throughput > 1 million RU/s), it's preferred to create separate virtual machines to concurrently execute the bulk operation API calls.
181
182
182
-
* Ensure the `InitializeAsync()` method is invoked after instantiating a BulkExecutor object to fetch the target Azure Cosmos DB container's partition map.
183
+
* Ensure the `InitializeAsync()` method is invoked after instantiating a BulkExecutor object to fetch the target Azure Cosmos DB container's partition map.
183
184
184
185
* In your application's App.Config, ensure **gcServer** is enabled for better performance
185
186
```xml
@@ -202,4 +203,4 @@ Consider the following points for better performance when using the bulk executo
202
203
203
204
## Next steps
204
205
205
-
* To learn about the NuGet package details and the release notes, see the [bulk executor SDK details](sdk-dotnet-bulk-executor-v2.md).
206
+
* To learn about the NuGet package details and the release notes, see [.NET bulk executor library: Download information (Legacy)](sdk-dotnet-bulk-executor-v2.md).
0 commit comments