-
Notifications
You must be signed in to change notification settings - Fork 354
Cosmos: Microbenchmark and some optimizations #4159
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
Merged
analogrelay
merged 23 commits into
Azure:release/azure_data_cosmos-previews
from
analogrelay:ashleyst/micro-benchmarks
Apr 20, 2026
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0ccb91d
Add criterion microbenchmarks for CosmosDriver with profiling
analogrelay 37d1006
bench: update with parameterizable simulated latency
analogrelay ee59050
bench: reorganize a bit
analogrelay 62cf7c1
bench: live benchmark
analogrelay b53f34c
bench: perfbench script
analogrelay dfb0787
fix: parse account properties into endpoint URLs once
analogrelay 0447fb3
fix: more optimal header reading
analogrelay db78504
fix: more optimal handling of resource paths
analogrelay e85287f
fix: slim down the account endpoint state using arcs
analogrelay c758ba6
fix: skip sync_account_properties when account properties unchanged
analogrelay 6dfdc50
fix: pre-allocate Headers map to avoid rehashing in hot path
analogrelay 3e72135
fix: pre-size auth strings to reduce allocations in hot path
analogrelay 0bcd1df
fix: eliminate name_path allocation by reusing ContainerReference::na…
analogrelay 3e553be
fix: cache EndpointKey in CosmosEndpoint to avoid per-request format
analogrelay 5f6648b
fixup: restore request/response header name split after cherry-pick c…
analogrelay c0f8a45
fix: address PR review comments
analogrelay 96f7e09
chore: clippy and refmt
analogrelay 31e9347
fix: docs issue
analogrelay 905d278
bench: remove dhat
analogrelay 3a68380
chore: spell check
analogrelay da55dfc
chore: update feature flags
analogrelay 8957849
spelling errors
analogrelay 5932fba
more spell checking
analogrelay 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
2 changes: 2 additions & 0 deletions
2
sdk/cosmos/azure_data_cosmos/src/fault_injection/http_client.rs
This file contains hidden or 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 hidden or 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 hidden or 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,29 @@ | ||
| [package] | ||
| name = "azure_data_cosmos_benchmarks" | ||
| version = "0.1.0" | ||
| description = "Benchmarks for the Azure Cosmos DB Rust driver" | ||
| publish = false | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
| rust-version.workspace = true | ||
|
|
||
| [[bench]] | ||
| name = "point_read" | ||
| harness = false | ||
|
|
||
| [dependencies] | ||
| async-trait.workspace = true | ||
| azure_core = { workspace = true } | ||
| azure_data_cosmos_driver = { path = "../azure_data_cosmos_driver", features = [ | ||
| "__internal_mocking", | ||
| ] } | ||
| tokio = { workspace = true, features = ["rt-multi-thread", "time"] } | ||
| url.workspace = true | ||
|
|
||
| [dev-dependencies] | ||
| criterion.workspace = true | ||
|
|
||
| [lints] | ||
| workspace = true | ||
This file contains hidden or 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,35 @@ | ||
| # azure_data_cosmos_benchmarks | ||
|
|
||
| Criterion benchmarks for the Azure Cosmos DB Rust driver. All benchmarks | ||
| replace the reqwest transport with an in-memory mock, so they measure driver | ||
| overhead only — routing, signing, retry state, response parsing, and session | ||
| token management — with no network I/O. | ||
|
|
||
| ## Running the benchmarks | ||
|
|
||
| ### Standard latency benchmark | ||
|
|
||
| ```sh | ||
| cargo bench -p azure_data_cosmos_benchmarks --bench point_read | ||
| ``` | ||
|
|
||
| Results are written to `target/criterion/point_read/`. | ||
|
|
||
| ### CPU flamegraph (pprof) | ||
|
|
||
| Pass `--profile-time <seconds>` to enable pprof sampling: | ||
|
|
||
| ```sh | ||
| cargo bench -p azure_data_cosmos_benchmarks --bench point_read -- --profile-time 30 | ||
| ``` | ||
|
|
||
| The flamegraph SVG is written to | ||
| `target/criterion/point_read/profile/point_read.svg`. | ||
|
|
||
| For readable symbol names, build with debug symbols: | ||
|
|
||
| ```sh | ||
| cargo bench -p azure_data_cosmos_benchmarks --profile bench --bench point_read -- --profile-time 30 | ||
| ``` | ||
|
|
||
|
|
82 changes: 82 additions & 0 deletions
82
sdk/cosmos/azure_data_cosmos_benchmarks/benches/point_read.rs
This file contains hidden or 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,82 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| //! Criterion benchmark for `CosmosDriver::execute_operation` — point read. | ||
| //! | ||
| //! By default the reqwest transport is replaced with an in-memory mock so that | ||
| //! the benchmark measures driver overhead (routing, signing, retry state, | ||
| //! response parsing, session token management) without any network I/O. | ||
| //! | ||
| //! Set `AZURE_BENCH_MODE=live` to run against a real Cosmos DB endpoint. See | ||
| //! `azure_data_cosmos_benchmarks::setup_live` for the required environment | ||
| //! variables. | ||
| //! | ||
| //! Cache priming (account metadata, container metadata) is performed in setup, | ||
| //! outside the measured iteration loop. | ||
| //! | ||
| //! # CPU flamegraph profiling | ||
| //! | ||
| //! Run with `--profile-time` to generate a flamegraph SVG via pprof: | ||
| //! | ||
| //! ```text | ||
| //! cargo bench -p azure_data_cosmos_benchmarks --bench point_read -- --profile-time 30 | ||
| //! ``` | ||
| //! | ||
| //! Output: `target/criterion/point_read/profile/flamegraph.svg` | ||
|
|
||
| use azure_data_cosmos_benchmarks::{self as common, BenchConfig}; | ||
|
|
||
| use std::time::Duration; | ||
|
|
||
| use azure_data_cosmos_driver::{models::CosmosOperation, options::OperationOptions}; | ||
| use criterion::{criterion_group, criterion_main, Criterion, Throughput}; | ||
| use tokio::runtime::Builder; | ||
|
|
||
| fn bench_point_read(c: &mut Criterion) { | ||
| let rt = Builder::new_current_thread() | ||
| .enable_all() | ||
| .build() | ||
| .expect("failed to create tokio runtime"); | ||
|
|
||
| let mut group = c.benchmark_group("point_read"); | ||
| group.throughput(Throughput::Elements(1)); | ||
|
|
||
| match common::load_bench_config() { | ||
| BenchConfig::Mock => { | ||
| let (driver, item_ref) = rt.block_on(common::setup()); | ||
| group.bench_function("mock", |b| { | ||
| b.to_async(&rt).iter(|| async { | ||
| driver | ||
| .execute_operation( | ||
| CosmosOperation::read_item(item_ref.clone()), | ||
| OperationOptions::default(), | ||
| ) | ||
| .await | ||
| .expect("execute_operation failed") | ||
| }); | ||
| }); | ||
| } | ||
| BenchConfig::Live => { | ||
| let (driver, item_ref) = rt.block_on(common::setup_live()); | ||
| group | ||
| .sample_size(50) | ||
| .measurement_time(Duration::from_secs(30)); | ||
| group.bench_function("live", |b| { | ||
| b.to_async(&rt).iter(|| async { | ||
| driver | ||
| .execute_operation( | ||
| CosmosOperation::read_item(item_ref.clone()), | ||
| OperationOptions::default(), | ||
| ) | ||
| .await | ||
| .expect("execute_operation failed") | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| criterion_group!(benches, bench_point_read); | ||
| criterion_main!(benches); |
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.
Uh oh!
There was an error while loading. Please reload this page.