Skip to content

Commit 870c06b

Browse files
committed
refresh and edits
1 parent d593e2b commit 870c06b

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

articles/cosmos-db/nosql/bulk-executor-dotnet.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ ms.service: cosmos-db
77
ms.subservice: nosql
88
ms.devlang: csharp
99
ms.topic: how-to
10-
ms.date: 05/02/2020
10+
ms.date: 03/14/2023
1111
ms.reviewer: mjbrown
1212
ms.custom: devx-track-csharp, ignite-2022
1313
---
1414

1515
# Use the bulk executor .NET library to perform bulk operations in Azure Cosmos DB
16+
1617
[!INCLUDE[NoSQL](../includes/appliesto-nosql.md)]
1718

1819
> [!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.
2021
2122
> 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.
2223
@@ -48,9 +49,9 @@ The "BulkImportSample" application generates random documents and bulk imports t
4849

4950
## <a id="bulk-import-data-to-an-azure-cosmos-account"></a>Bulk import data to an Azure Cosmos DB account
5051

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.
5253

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:
5455

5556
```csharp
5657
private static readonly string EndpointUrl = ConfigurationManager.AppSettings["EndPointUrl"];
@@ -62,7 +63,7 @@ The "BulkImportSample" application generates random documents and bulk imports t
6263

6364
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.
6465

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:
6667

6768
```csharp
6869
ConnectionPolicy connectionPolicy = new ConnectionPolicy
@@ -74,7 +75,7 @@ The "BulkImportSample" application generates random documents and bulk imports t
7475
connectionPolicy)
7576
```
7677

77-
4. The BulkExecutor object is initialized with a high retry value for wait time and throttled requests. And then they're set to 0 to pass congestion control to BulkExecutor for its lifetime.
78+
1. The BulkExecutor object is initialized with a high retry value for wait time and throttled requests. And then they're set to 0 to pass congestion control to BulkExecutor for its lifetime.
7879

7980
```csharp
8081
// Set retry options high during initialization (default values).
@@ -89,7 +90,7 @@ The "BulkImportSample" application generates random documents and bulk imports t
8990
client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0;
9091
```
9192

92-
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).
9394

9495
```csharp
9596
BulkImportResponse bulkImportResponse = await bulkExecutor.BulkImportAsync(
@@ -101,8 +102,8 @@ The "BulkImportSample" application generates random documents and bulk imports t
101102
cancellationToken: token);
102103
```
103104
**BulkImportAsync method accepts the following parameters:**
104-
105-
|**Parameter** |**Description** |
105+
106+
|**Parameter** |**Description** |
106107
|---------|---------|
107108
|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. |
108109
|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
113114
**Bulk import response object definition**
114115
The result of the bulk import API call contains the following attributes:
115116

116-
|**Parameter** |**Description** |
117+
|**Parameter** |**Description** |
117118
|---------|---------|
118119
|NumberOfDocumentsImported (long) | The total number of documents that were successfully imported out of the total documents supplied to the bulk import API call. |
119120
|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
124125

125126
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).
126127

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.
128129

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).
130131

131132
```csharp
132133
SetUpdateOperation<string> nameUpdate = new SetUpdateOperation<string>("Name", "UpdatedDoc");
@@ -143,7 +144,7 @@ You can update existing documents by using the BulkUpdateAsync API. In this exam
143144
}
144145
```
145146

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).
147148

148149
```csharp
149150
BulkUpdateResponse bulkUpdateResponse = await bulkExecutor.BulkUpdateAsync(
@@ -154,7 +155,7 @@ You can update existing documents by using the BulkUpdateAsync API. In this exam
154155
```
155156
**BulkUpdateAsync method accepts the following parameters:**
156157

157-
|**Parameter** |**Description** |
158+
|**Parameter** |**Description** |
158159
|---------|---------|
159160
|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). |
160161
|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
163164
**Bulk update response object definition**
164165
The result of the bulk update API call contains the following attributes:
165166

166-
|**Parameter** |**Description** |
167+
|**Parameter** |**Description** |
167168
|---------|---------|
168169
|NumberOfDocumentsUpdated (long) | The number of documents that were successfully updated out of the total documents supplied to the bulk update API call. |
169170
|TotalRequestUnitsConsumed (double) | The total request units (RUs) consumed by the bulk update API call. |
170171
|TotalTimeTaken (TimeSpan) | The total time taken by the bulk update API call to complete the execution. |
171-
172-
## Performance tips
172+
173+
## Performance tips
173174

174175
Consider the following points for better performance when using the bulk executor library:
175176

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.
177178

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.
179180

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.
181182

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.
183184

184185
* In your application's App.Config, ensure **gcServer** is enabled for better performance
185186
```xml
@@ -202,4 +203,4 @@ Consider the following points for better performance when using the bulk executo
202203

203204
## Next steps
204205

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

Comments
 (0)