Commit fdc2a54
feat(cosmos/workloads): add performance metrics collection for DR drill testing (#46271)
* fix(workloads): use concurrent operations in r_w_q_workload, set 1M throughput
- Uncomment concurrent upsert/read/query calls
- Remove manual timing counters and log_request_counts
- Set THROUGHPUT to 1000000 in workload_configs.py
- Keep CIRCUIT_BREAKER_ENABLED = False (PPCB disabled)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat(workloads): add performance metrics collection for DR drill testing
Add a performance metrics library that reports PerfResult documents to a
Cosmos DB results account, matching the Rust perf tool schema exactly so
both SDKs feed the same ADX → Grafana pipeline.
New files:
- perf_stats.py: Thread-safe latency histogram with sorted-list percentile
calculation and atomic drain_all() for consistent summary+error snapshots
- perf_config.py: All config from environment variables (RESULTS_COSMOS_URI,
PERF_REPORT_INTERVAL=300s, perfdb/perfresults defaults)
- perf_reporter.py: Background daemon thread that drains Stats every 5 min
and upserts PerfResult documents via sync CosmosClient with AAD auth
Modified files:
- workload_configs.py: All configs now driven by environment variables
- workload_utils.py: Added timed operation wrappers with error tracking
(CosmosHttpResponseError status_code/sub_status extraction), only
successful operations record latency to avoid polluting percentiles
- All *_workload.py files: Integrated Stats + PerfReporter with try/finally
lifecycle management
Key design decisions:
- Sorted-list percentiles (no hdrhistogram native dependency)
- psutil for CPU/memory with /proc fallback on Linux
- Cached psutil.Process() instance for accurate CPU readings
- CosmosClient stored and closed properly to avoid resource leaks
- sdk_language='python', sdk_version from azure.cosmos.__version__
- PPCB disabled by default
- All reporter errors caught and logged as warnings (never crash workload)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): require psutil, remove /proc fallback code
psutil is now a hard import (not optional). Removed all /proc/meminfo
and /proc/self/status fallback parsing — if psutil is not installed,
the import will fail immediately rather than silently degrading.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* refactor(workloads): unify to single workload.py with env-var config
- Single workload.py replaces 6 operation-specific files
- WORKLOAD_OPERATIONS env var controls which ops run (read,write,query)
- WORKLOAD_USE_PROXY env var enables Envoy proxy routing
- WORKLOAD_USE_SYNC env var enables sync client
- Validate operation names at import time with clear error
- Replace manual sorted-list percentiles with hdrhistogram (O(1) record/query)
- Fixed memory usage (~40KB per histogram vs unbounded list growth)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* refactor(workloads): delete old workload files replaced by unified workload.py
Removed: r_workload.py, w_workload.py, r_proxy_workload.py,
w_proxy_workload.py, r_w_q_workload.py, r_w_q_proxy_workload.py,
r_w_q_sync_workload.py
All replaced by workload.py with WORKLOAD_OPERATIONS and
WORKLOAD_USE_PROXY env vars.
Kept: r_w_q_with_incorrect_client_workload.py (special test case)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat(workloads): add WORKLOAD_SKIP_CLOSE to simulate unclosed clients
Replaces r_w_q_with_incorrect_client_workload.py with an env var:
WORKLOAD_SKIP_CLOSE=true creates the client without a context manager,
simulating applications that don't properly close the Cosmos client.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* perf(workloads): use perf_counter_ns for higher precision timing
Switch from time.perf_counter() * 1000 to time.perf_counter_ns() / 1_000_000
for nanosecond precision without floating-point multiplication artifacts.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* refactor(workloads): remove run_workloads.sh and dev.md
Infra/orchestration scripts belong in the cosmos-sdk-copilot-toolkit repo,
not in the SDK repo. Workload code (workload.py, perf_*, workload_utils.py)
stays here.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): correct hdrhistogram import — module is hdrh not hdrhistogram
The pip package is 'hdrhistogram' but the Python module is 'hdrh'.
Import changed from 'from hdrhistogram import HdrHistogram' to
'from hdrh.histogram import HdrHistogram'.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): use get_mean_value() for hdrh API
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* style(workloads): fix black formatting and setup_env.sh references
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat(workloads): add config_multi_write_enabled to PerfResult
Reports COSMOS_USE_MULTIPLE_WRITABLE_LOCATIONS in the config snapshot
so it's visible in the Grafana dashboard and queryable from Kusto.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): define multi_write variable in perf_reporter
The variable was used but never defined — caused pylint E0602.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): address review findings — lazy imports, session close, histogram clamp, safe parsing
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): add perfdb, perfresults, ppcb, hdrh to cosmos cspell dictionary
Move cspell words to sdk/cosmos/azure-cosmos/cspell.json instead of
root .vscode/cspell.json to keep changes within cosmos folder scope.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): use RESULTS_COSMOS_KEY when available, fallback to DefaultAzureCredential
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat(workloads): add config_proxy_enabled and config_skip_close to PerfResult
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* refactor(workloads): remove setup_env.sh — moved to cosmos-sdk-copilot-toolkit
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* refactor(workloads): deduplicate timed operations with shared helpers
Extract _extra_kwargs(), _timed_call(), and _timed_call_async() to
eliminate duplicated excluded_locations branching and timing/error
recording across 6 operation functions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): address review — public import, sync+proxy fail-fast, flush lock
1. Use public azure.core.pipeline.transport import for AioHttpTransport
2. Fail fast with RuntimeError if WORKLOAD_USE_SYNC + WORKLOAD_USE_PROXY
3. Add threading.Lock around _flush(), skip final flush if thread alive
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): re-enable WorkloadLoggerFilter to reduce log noise
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): rename coro to coroutine/awaitable to fix cspell errors
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* ci: retrigger pipeline
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat(workloads): add WORKLOAD_NUM_CLIENTS for multi-client memory profiling
Allows spawning multiple CosmosClient instances in a single process
via WORKLOAD_NUM_CLIENTS env var (default: 1). Useful for reproducing
memory scaling issues with many client instances.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): cap error buffer at 2000, fix sync query variable capture
- perf_stats: Replace unbounded _errors list with deque(maxlen=2000).
Errors at this level are minimal due to SDK internal retries.
- workload_utils: Capture loop variable in sync query_items with
def _do_query(ri=random_item) to match async pattern.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(workloads): address review — shared reporter, safe ints, consolidated helpers
1. Share Stats+PerfReporter across multi-client tasks (single workload_id)
2. Remove drain_summaries/drain_errors (use drain_all only)
3. Revert THROUGHPUT default to 100K (set COSMOS_THROUGHPUT=1000000 for DR drills)
4. Use _safe_int for all int env vars in workload_configs.py
5. Add try/except to sync reporter.stop() matching async path
6. Move circuit breaker env var from create_logger to workload_configs
7. Consolidate duplicated client constructor
8. Add TIMESTAMP schema compatibility comment
9. Consolidate _safe_int_env into perf_config.py
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent bec9bd8 commit fdc2a54
18 files changed
Lines changed: 887 additions & 585 deletions
File tree
- sdk/cosmos/azure-cosmos
- tests/workloads
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
Lines changed: 253 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
0 commit comments