Repository navigation
[Cosmos] Reduce Change Feed Processor lease write response overhead - #50697
Open
Kushagra Thapar (kushagraThapar) wants to merge 5 commits into
Open
Kushagra Thapar (kushagraThapar) wants to merge 5 commits into
Kushagra Thapar (kushagraThapar) wants to merge 5 commits into
Conversation
Change Feed Processor lease writes (lease replace, lease create, store marker and initialization lock) now always disable content response on write. The cached lease keeps its submitted state and the new ETag is taken from the response headers, so optimistic concurrency keeps working. The lease container client no longer needs contentResponseOnWrite enabled. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ae1fde61-d6d9-4ea8-9e25-9442e4cab19a
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ae1fde61-d6d9-4ea8-9e25-9442e4cab19a
Member
Author
|
/azp run java - cosmos - tests |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
Member
Author
|
/azp run java - cosmos - tests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 33 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Member
Author
|
/azp run java - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Remove alwaysRun from @BeforeClass so the test class does not build clients or create resources in unrelated live suites, and use the shared test database like the other CFP tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ae1fde61-d6d9-4ea8-9e25-9442e4cab19a
Member
Author
|
/azp run java - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Resolve the Cosmos changelog conflict while retaining upstream updates and documenting bandwidth and client-processing benefits without RU savings. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Kushagra Thapar (kushagraThapar)
marked this pull request as ready for review
October 29, 2026 15:50
Kushagra Thapar (kushagraThapar)
requested review from
a team and
Kiran Kumar Kolli (kirankumarkolli)
as code owners
October 29, 2026 15:50
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The emulator/live scenarios were not run, leaving lease concurrency, restart continuity, header ETag propagation, and conditional lock release unverified against actual bodyless service responses.
No open issues 🎉
What changed in this PR
Reduces Azure Cosmos DB Change Feed Processor lease-write response overhead across PK and EPK implementations, without changing RU charges or the at-least-once delivery contract.
Changes:
- Disables response bodies for lease creates and replaces, preserving local lease state and updating ETags from response headers.
- Allows lease clients configured with content responses disabled.
- Adds unit and integration coverage for ETag chaining, recovery, initialization, and checkpoint resume; documents the efficiency improvement.
| File | Description |
|---|---|
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/pkversion/LeaseStoreManagerImpl.java |
Handles bodyless PK lease creation using header ETags. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/pkversion/LeaseStoreImpl.java |
Disables initialization response bodies and captures lock ETags. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/pkversion/IncrementalChangeFeedProcessorImpl.java |
Removes the requirement for enabled lease-client response content. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/pkversion/DocumentServiceLeaseUpdaterImpl.java |
Preserves PK lease state and refreshes ETags after bodyless replaces. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/epkversion/LeaseStoreManagerImpl.java |
Handles bodyless EPK lease creation using header ETags. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/epkversion/LeaseStoreImpl.java |
Applies bodyless initialization writes and header-based lock ETags. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/epkversion/DocumentServiceLeaseUpdaterImpl.java |
Preserves EPK lease state and refreshes ETags after bodyless replaces. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/epkversion/ChangeFeedProcessorImplBase.java |
Accepts lease clients with response content disabled. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/common/ChangeFeedHelper.java |
Adds a shared helper to disable write response content. |
sdk/cosmos/azure-cosmos/CHANGELOG.md |
Documents reduced response overhead and unchanged RU charges. |
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/rx/changefeed/ChangeFeedProcessorLeaseWithoutContentResponseTest.java |
Adds end-to-end checkpoint and resume scenarios across processor modes. |
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/changefeed/pkversion/LeaseWritesWithoutContentResponseTests.java |
Covers PK bodyless writes, ETag recovery, initialization, and builder acceptance. |
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/changefeed/epkversion/LeaseWritesWithoutContentResponseTests.java |
Covers EPK bodyless writes, ETag recovery, initialization, and handler acceptance. |
Review effort: Balanced
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Disable response bodies for CFP lease creates/replaces in both PK and EPK implementations. CFP retains the submitted lease and applies the response-header ETag, preserving conditional-write behavior without deserializing a returned lease body.
This reduces response bandwidth and client processing, not RU/write. Feed operations and CFP's at-least-once contract are unchanged. Related: Azure/azure-cosmos-dotnet-v3#6147.
Changes
Benchmark: million-RU feed (2026-10-29)
Blue = baseline; teal = this PR. Bars start at zero; diamonds show median within-pair changes, not confidence intervals.
Setup
Dedicated D16s_v5 VM (16 vCPU / 64 GiB), East US 2; JDK 17, 2 GiB heap/G1GC, Direct mode, Session consistency, single region. PK-range
handleChanges, batch 100, checkpoint per batch; lease renew/acquire/expiration 17/13/60 seconds. Alternating order: B/T, T/B, B/T. No concurrent producer; every range stayed active throughout measurement. EPK processing was not separately benchmarked.Baseline:
17341a305be1739bd899736c4057e493230c80b3; treatment:8eea6f11f06d8de30f2646e2a49c7ea04aaf2329. The 59 external JARs were identical.Results
Bandwidth savings were measured directly, using successful Direct transport responses. The 49.3% reduction applies to lease-write RNTBD responses, not total application traffic or TLS/TCP/IP overhead.
Performance limitation: leases recorded 35,428-43,823 transport 429s/arm; feed 429s were zero and CPU used approximately 2.1/16 cores. Three pairs do not establish throughput/CPU gains. CPU is whole-JVM; allocation figures are JFR sampling estimates.
Large-customer scenarios: extrapolation, not measured results
Logical keys are not CFP leases: our 65,536 keys mapped to 100 physical/feed ranges and 100 partition leases. The scenarios below model 50k-100k owned leases across a fleet, not merely that many logical keys or capacity on one VM.
The approximately 507-byte difference saved roughly 0.48 MB/s at our observed approximately 950 replacements/s. Assuming similar response sizes, stable ownership and sustained stated write cadences:
These are avoided bytes, not guaranteed cost savings (decimal units). Each row excludes the other write type. Actual savings depend on lease size, activity and checkpoint/renewal cadence.
Hypothesis: high-write-rate fleets can avoid substantial redundant traffic and lease-body parsing/allocation. CPU/GC headroom at 50k-100k leases remains unvalidated; do not multiply the observed allocation percentage by partition count. RU/write, write count, request size, storage and lease-management work remain unchanged. This does not fix lease throttling or prove fewer VMs/pods are needed.
All six measured arms
Execution order below. CPU/allocation use measured-window documents, not full-drain counts.
All six arms subsequently drained 63,355,852 unique documents, persisted/reacquired all 100 leases and observed zero duplicates, foreign IDs or restart replay. These checks were outside measurement and do not imply exactly-once delivery.
Exact six-run CSV
Transport counters include retry responses; RU excludes gateway-only metadata charges. Source hashes identify the retained original arm JSONs. Rejected calibration/seed attempts are excluded.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines
New tests
PK/EPK coverage includes header-ETag chaining, body-present compatibility, conflicts/recovery, initialization and builder acceptance. Integration scenarios cover checkpoint persistence and restart; they were compiled but not executed in the local validation below.
Validation
Passed: Cosmos library/test-source compilation and 120 change-feed unit tests, zero failures/errors/skips (2026-10-28). Checkstyle passed; full CI is not claimed green.
Exact commands, environment and exclusions
After merging
origin/mainat17341a305be1739bd899736c4057e493230c80b3and resolving the changelog conflict: Maven 3.9.10, JDK 17.0.12. SetJAVA_HOME/PATHto JDK 17 and exportMAVEN_SKIP_RC=trueto prevent local Maven startup overrides. Run from the repository root.Passed: BUILD SUCCESS, library packaging/install and test-source compilation; zero Checkstyle violations.
mvn -B -ntp -f sdk/cosmos/azure-cosmos-tests/pom.xml verify -Punit '-Dit.test=com.azure.cosmos.implementation.changefeed.**.*Test*' -Dfailsafe.failIfNoTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -Dcodesnippet.skip=true -Drevapi.skip=true -Djacoco.skip=truePassed: BUILD SUCCESS; 120 tests, 0 failures, 0 errors, 0 skipped.
Not run in this local validation: emulator/live integration suites, full repository build, SpotBugs, Javadoc, snippet verification, API compatibility and coverage checks.