Repository navigation
feat(streaming): adapt Event Hubs cache memory usage - #10316
ReubenBond wants to merge 28 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces and bounds Event Hubs streaming-cache memory usage by introducing provider-wide memory accounting, adaptive buffer sizing/pooling, and adaptive cached-message metadata blocks, with new configuration options and targeted tests validating the new behavior.
Changes:
- Introduces provider-wide active-cache memory accounting for Event Hubs and an adaptive payload buffer pool with bounded idle retention.
- Makes cached-message metadata blocks adaptive (start small, grow up to a max, shrink on reset) and adds active-metadata size tracking.
- Adds
EventHubStreamCacheMemoryOptions(+ validation and builder extensions) and new tests covering adaptive behavior and defaults.
Show a summary per file
| File | Description |
|---|---|
| test/Orleans.Streaming.Tests/OrleansRuntime/Streams/PooledQueueCacheTests.cs | Adds a regression test ensuring adaptive metadata blocks are released when the cache drains. |
| test/Orleans.Streaming.Tests/OrleansRuntime/Streams/FixedSizeBufferTests.cs | Adds a test verifying the new object-pool retention cap behavior. |
| test/Orleans.Streaming.Tests/OrleansRuntime/Streams/CachedMessageBlockTests.cs | Adds a test validating CachedMessageBlock geometric growth and shrink-on-reset behavior. |
| test/Extensions/Orleans.Streaming.EventHubs.Tests/CacheMemoryTests.cs | Adds integration-style tests validating default bounds, size classes, aggregation across partitions, and custom pool compatibility. |
| src/Orleans.Streaming/Common/PooledCache/PooledQueueCache.cs | Adds adaptive cached-message block support, tracks active metadata allocation, and implements IDisposable. |
| src/Orleans.Streaming/Common/PooledCache/ObjectPool.cs | Adds maxRetainedObjects to bound retained pooled objects and adjusts monitoring counters accordingly. |
| src/Orleans.Streaming/Common/PooledCache/ChronologicalEvictionStrategy.cs | Adds explicit buffer release APIs and IDisposable support for releasing in-use buffers. |
| src/Orleans.Streaming/Common/PooledCache/CachedMessagePool.cs | Updates block allocation/reuse to support adaptive sizing and bounded retention; reports allocation deltas. |
| src/Orleans.Streaming/Common/PooledCache/CachedMessageBlock.cs | Implements adaptive growth/shrink behavior and exposes allocated-size accounting. |
| src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubStreamOptions.cs | Introduces EventHubStreamCacheMemoryOptions and validator with bounded defaults. |
| src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubStreamBuilder.cs | Adds ConfigureCacheMemory and registers options+validator for logging/validation. |
| src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubQueueCacheFactory.cs | Uses a shared memory controller and adaptive buffer pool; adds a memory-pressure eviction strategy. |
| src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubQueueCache.cs | Integrates metadata accounting and memory-pressure behavior; adapts message-block sizing and buffer sizing. |
| src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubCacheMemoryController.cs | Adds new controller and adaptive buffer pool implementation with size classes and bounded idle memory. |
| src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubAdapterReceiver.cs | Ensures purging is triggered for Event Hubs caches experiencing memory pressure. |
| src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubAdapterFactory.cs | Wires named EventHubStreamCacheMemoryOptions through to cache factory creation. |
| src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventDataGeneratorStreamConfigurator.cs | Registers cache-memory options and validator for the generator provider configuration surface. |
| src/Azure/Orleans.Streaming.EventHubs/Providers/EventDataGeneratorStreamProvider/EventDataGeneratorAdapterFactory.cs | Wires cache-memory options through for the generator adapter factory. |
| src/api/Orleans.Streaming/Orleans.Streaming.cs | Updates public API surface for adaptive blocks, bounded pools, and new IDisposable members. |
| src/api/Azure/Orleans.Streaming.EventHubs/Orleans.Streaming.EventHubs.cs | Updates public API surface for Event Hubs cache-memory options and new constructor overloads. |
Copilot's findings
- Files reviewed: 20/20 changed files
- Comments generated: 2
8515add to
f50ca83
Compare
d457abb to
f2226e2
Compare
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventDataGeneratorStreamConfigurator.cs:47
- The service-registration fluent chain has irregular spacing/indentation (notably the large gap before
.ConfigureNamedOptionForLogging) which makes this block hard to read and can generate formatting noise in future diffs. Reformat the chain so each call is on its own consistently-indented line.
this.ConfigureDelegate(services => services .ConfigureNamedOptionForLogging<EventHubOptions>(name)
.ConfigureNamedOptionForLogging<EventHubReceiverOptions>(name)
.ConfigureNamedOptionForLogging<EventHubStreamCachePressureOptions>(name)
.ConfigureNamedOptionForLogging<EventHubStreamCacheMemoryOptions>(name)
.AddTransient<IConfigurationValidator>(sp => new EventHubStreamCacheMemoryOptionsValidator(sp.GetOptionsByName<EventHubStreamCacheMemoryOptions>(name), name))
- Files reviewed: 20/20 changed files
- Comments generated: 0 new
- Review effort level: Lite
f2226e2 to
f4d8085
Compare
There was a problem hiding this comment.
Review details
Suppressed comments (3)
Previously missed (3) — in code that hasn't changed since the last review.
src/Orleans.Streaming/Common/PooledCache/ObjectPool.cs:15
DefaultPoolCapacityis now unused. Keeping unused constants can trigger analyzers (and fail the build when code style is enforced). Remove it (or reintroduce a capacity check if it’s still intended).
private const int DefaultPoolCapacity = 1 << 10; // 1k
test/Orleans.Streaming.Tests/OrleansRuntime/Streams/FixedSizeBufferTests.cs:3
using Orleans.Streams;is unused in this test file and can trigger IDE0005 (unused using) under enforced code style. Remove the unused using directive.
using Orleans.Streams;
test/Extensions/Orleans.Streaming.EventHubs.Tests/CacheMemoryTests.cs:91
- This test is only marked with
[Fact], so it won’t be included when running BVT viaCategory=BVTfilters (other tests in this file explicitly addTestCategory("BVT")). Add the missing category so it runs in the same CI selection.
[Fact]
- Files reviewed: 20/20 changed files
- Comments generated: 0 new
- Review effort level: Lite
8a0ebb9 to
631c7ff
Compare
631c7ff to
9ab466e
Compare
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 7046c02b-4a9b-4623-9183-99472770f6fd
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 7046c02b-4a9b-4623-9183-99472770f6fd
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
4 open issues
EventHubCacheBufferPool’s constructor takes a non-nullTimeSpan monitorInterval, but… · NewResetCore()clears only the range[readIndex, writeIndex). When the block is emptied via reads… · New Prevent stalls when delivery boundary splits the oldest buffer Boundary-spanning buffers can block memory reclamation indefinitely
Review effort: Lite


Event Hubs currently incurs large first-touch cache allocations per partition and retains peak cache capacity indefinitely. With systems containing hundreds or thousands of sparse partitions, this can consume substantial memory even when little stream data is active.
This change makes Event Hubs cache storage adaptive and bounded. Cached-message metadata and payload buffers now start small and grow as needed, idle payload retention is capped, and active cache memory is controlled across all partitions for a provider. Memory-pressure recovery reclaims one oldest payload buffer at a time while preserving slow-consumer protection and custom buffer-pool compatibility.
When memory pressure stops reads, the pulling agent publishes the settled delivery boundary and retries capacity. Event Hubs reclaims data through that boundary synchronously, allowing caught-up subscriptions to remain registered while ingestion resumes. Pending registrations, handshakes, and in-flight deliveries retain their required data. Recovery progresses even when paused ingestion keeps the cached enqueue-time span constant.
The default provider-wide active-cache high watermark is 512 MiB and the idle payload-pool limit is 64 MiB. Batches already in flight may temporarily exceed the watermark while their events remain available for ordered delivery.
Microsoft Reviewers: Open in CodeFlow