-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bulk enhancement with dynamic congestion control #32567
Open
aditishree1
wants to merge
45
commits into
main
Choose a base branch
from
bulk-congestion-control
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 37 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
bfbfa4b
modified bulk implementation
5b0432c
remove logs
19a940a
add bulkExecutionRetryPolicy and update response
f3cfd89
remove errors
a8d50fb
rush format
cc88b23
add congestion control logic
9984c3c
remove internal tag
3cfb4da
format
12f231c
remove executor cache usage
c4aca61
delete resources from executor and add checks for semaphore
eb9b281
modify public methods
2b1a23d
format
9a31b46
add option to pass a list of operations
ffc2a07
format
831336d
fix container leaking in tests
68bc101
add bulk request handler and fix operation Index
0206c2e
fix retry error and degree of concurrency
42a9d5d
Add limiter to stop batches on 410
amanrao23 2dd3ea4
fix bulk retry
f10ec1f
refactor addBulkOperations
9b1cd73
add ReadWriteLock test cases
amanrao23 4444062
skip bulk split tests temporarily
amanrao23 d70b07a
fix algo and add unit test
2e03115
add test cases
52c0c3e
format
d11fde7
remove bulkOptions
81cc3f6
modify api names, fix errors
1fea1e1
add unit test for bulk execution retry policy
6a55eb2
add lock on partition metric add method
b6fc416
reset wait time when increasing concurrency
4d47f1e
remove congestion timer
8d38448
modify limiter
f4e24ca
add doc comments and samples
ad1b6ca
add comment to response class
a5aa756
remove bulkStreamer cache
a0b62e8
refactor names and modify comment
7f82e21
remove separate operation index, add checks and test
0c3aaff
refactor names and add comments
6e68420
address comments
63ebbbd
add lock on operationIndex
8c8eb80
add comment for TODO
a25b5e8
remove redundant tests
9d89d0c
Merge branch 'main' into bulk-congestion-control
f415870
format
028d437
extend operation response and add lock to degree of concurrency
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* @summary Demonstrates example of bulk stream operations. | ||
*/ | ||
|
||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
import { handleError, finish, logStep } from "./Shared/handleError"; | ||
import type { OperationInput } from "@azure/cosmos"; | ||
import { CosmosClient } from "@azure/cosmos"; | ||
|
||
const key = process.env.COSMOS_KEY || "<cosmos key>"; | ||
const endpoint = process.env.COSMOS_ENDPOINT || "<cosmos endpoint>"; | ||
|
||
async function run(): Promise<void> { | ||
const containerId = "bulkStreamerContainer"; | ||
const client = new CosmosClient({ | ||
key: key, | ||
endpoint: endpoint, | ||
}); | ||
const { database } = await client.databases.create({ id: "bulkStreamer db" }); | ||
logStep(`Creating multi-partition container '${containerId}' with partition key /key`); | ||
const { container } = await database.containers.create({ | ||
id: containerId, | ||
partitionKey: { | ||
paths: ["/key"], | ||
version: 2, | ||
}, | ||
throughput: 1000, | ||
}); | ||
|
||
logStep("Preparing 10 'Create' operations"); | ||
const createOperations: OperationInput[] = Array.from({ length: 10 }, (_, index) => ({ | ||
operationType: "Create", | ||
resourceBody: { | ||
id: `doc${index + 1}`, | ||
name: `sample${index + 1}`, | ||
key: `${index + 1}`, | ||
}, | ||
})); | ||
|
||
logStep("Preparing a 'Read' operation for 'doc1'"); | ||
const readOperation: OperationInput = { operationType: "Read", id: "doc1", partitionKey: "1" }; | ||
|
||
logStep(`Getting a Bulk Streamer instance`); | ||
const bulkStreamer = container.items.getBulkStreamer(); | ||
|
||
// an operation or a list of operations could be provided as input to addOperations | ||
logStep("Adding the list of 'Create' operations to the Bulk Streamer"); | ||
bulkStreamer.addOperations(createOperations); | ||
logStep("Adding a single 'Read' operation to the Bulk Streamer..."); | ||
bulkStreamer.addOperations(readOperation); | ||
|
||
logStep("Ending the bulk stream"); | ||
const response = await bulkStreamer.endStream(); | ||
console.log("Bulk Response: ", response); | ||
|
||
await finish(); | ||
} | ||
|
||
run().catch(handleError); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* @summary Demonstrates example of bulk stream operations. | ||
*/ | ||
|
||
require("dotenv").config(); | ||
|
||
const { handleError, finish, logStep } = require("./Shared/handleError"); | ||
const { CosmosClient } = require("@azure/cosmos"); | ||
|
||
const key = process.env.COSMOS_KEY || "<cosmos key>"; | ||
const endpoint = process.env.COSMOS_ENDPOINT || "<cosmos endpoint>"; | ||
|
||
async function run() { | ||
const containerId = "bulkStreamerContainer"; | ||
const client = new CosmosClient({ | ||
key: key, | ||
endpoint: endpoint, | ||
}); | ||
const { database } = await client.databases.create({ id: "bulkStreamer db" }); | ||
logStep(`Creating multi-partition container '${containerId}' with partition key /key`); | ||
const { container } = await database.containers.create({ | ||
id: containerId, | ||
partitionKey: { | ||
paths: ["/key"], | ||
version: 2, | ||
}, | ||
throughput: 1000, | ||
}); | ||
|
||
logStep("Preparing 10 'Create' operations"); | ||
const createOperations = Array.from({ length: 10 }, (_, index) => ({ | ||
operationType: "Create", | ||
resourceBody: { | ||
id: `doc${index + 1}`, | ||
name: `sample${index + 1}`, | ||
key: `${index + 1}`, | ||
}, | ||
})); | ||
|
||
logStep("Preparing a 'Read' operation for 'doc1'"); | ||
const readOperation = { operationType: "Read", id: "doc1", partitionKey: "1" }; | ||
|
||
logStep(`Getting a Bulk Streamer instance`); | ||
const bulkStreamer = container.items.getBulkStreamer(); | ||
|
||
// an operation or a list of operations could be provided as input to addOperations | ||
logStep("Adding the list of 'Create' operations to the Bulk Streamer"); | ||
bulkStreamer.addOperations(createOperations); | ||
logStep("Adding a single 'Read' operation to the Bulk Streamer..."); | ||
bulkStreamer.addOperations(readOperation); | ||
|
||
logStep("Ending the bulk stream"); | ||
const response = await bulkStreamer.endStream(); | ||
console.log("Bulk Response: ", response); | ||
|
||
await finish(); | ||
} | ||
|
||
run().catch(handleError); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
sdk/cosmosdb/cosmos/samples/v4/typescript/src/BulkStreamer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* @summary Demonstrates example of bulk stream operations. | ||
*/ | ||
|
||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
import { handleError, finish, logStep } from "./Shared/handleError"; | ||
import type { | ||
OperationInput, | ||
} from "@azure/cosmos"; | ||
import { | ||
CosmosClient | ||
} from "@azure/cosmos"; | ||
|
||
const key = process.env.COSMOS_KEY || "<cosmos key>"; | ||
const endpoint = process.env.COSMOS_ENDPOINT || "<cosmos endpoint>"; | ||
|
||
|
||
async function run(): Promise<void> { | ||
const containerId = "bulkStreamerContainer"; | ||
const client = new CosmosClient({ | ||
key: key, | ||
endpoint: endpoint, | ||
}); | ||
const { database } = await client.databases.create({ id: ("bulkStreamer db") }); | ||
logStep(`Creating multi-partition container '${containerId}' with partition key /key`); | ||
const { container } = await database.containers.create({ | ||
id: containerId, | ||
partitionKey: { | ||
paths: ["/key"], | ||
version: 2, | ||
}, | ||
throughput: 1000, | ||
}); | ||
|
||
logStep("Preparing 10 'Create' operations") | ||
const createOperations: OperationInput[] = Array.from({ length: 10 }, (_, index) => ({ | ||
operationType: "Create", | ||
resourceBody: { | ||
id: `doc${index + 1}`, | ||
name: `sample${index + 1}`, | ||
key: `${index + 1}`, | ||
}, | ||
})); | ||
|
||
logStep("Preparing a 'Read' operation for 'doc1'") | ||
const readOperation: OperationInput = { operationType: "Read", id: "doc1", partitionKey: "1" }; | ||
|
||
logStep(`Getting a Bulk Streamer instance`); | ||
const bulkStreamer = container.items.getBulkStreamer(); | ||
|
||
// an operation or a list of operations could be provided as input to addOperations | ||
logStep("Adding the list of 'Create' operations to the Bulk Streamer"); | ||
bulkStreamer.addOperations(createOperations); | ||
logStep("Adding a single 'Read' operation to the Bulk Streamer...") | ||
bulkStreamer.addOperations(readOperation); | ||
|
||
logStep("Ending the bulk stream"); | ||
const response = await bulkStreamer.endStream(); | ||
console.log("Bulk Response: ", response); | ||
|
||
await finish(); | ||
} | ||
|
||
run().catch(handleError); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for adding bulk in the names? Can't it be just Operations count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not any specific reason. we are using these constants for bulk, that's why. Should we change these? In .Net, these are named as
MaxOperationsInDirectModeBatchRequest
andDefaultMaxBulkRequestBodySizeInBytes