[improve][client] PIP-234: Support sharing the memory limit controller across multiple isolated Pulsar client instances#25477
Open
oneby-wang wants to merge 11 commits intoapache:masterfrom
Open
Conversation
nodece
reviewed
Apr 7, 2026
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
Outdated
Show resolved
Hide resolved
nodece
approved these changes
Apr 7, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds support for sharing a single MemoryLimitController across multiple isolated Pulsar client instances (PIP-234), including multi-trigger registration/deregistration and tests that validate shared-memory behavior for producers and consumers.
Changes:
- Extend
MemoryLimitControllerto support multiple triggers and allow deregistration on client shutdown. - Add shared-resource support for a shared
MemoryLimitController(and associated OpenTelemetry wiring/metrics scaffolding) viaPulsarClientSharedResources. - Add integration tests validating shared memory limiting across multiple clients.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientSharedResourcesImpl.java | Instantiates and applies shared memory limit controller; optionally creates shared memory buffer metrics |
| pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientSharedResourcesBuilderImpl.java | Adds builder config objects and builder methods for shared memory limit and OpenTelemetry |
| pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientResourcesConfigurer.java | Adds factory methods to create shared MemoryLimitController and InstrumentProvider |
| pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java | Accepts injected shared MemoryLimitController, registers trigger, and deregisters on shutdown |
| pulsar-client/src/main/java/org/apache/pulsar/client/impl/MemoryLimitController.java | Supports multiple trigger callbacks via CopyOnWriteArraySet and exposes register/deregister |
| pulsar-client-api/src/main/java/org/apache/pulsar/client/api/PulsarClientSharedResourcesBuilder.java | Adds public builder methods for shared memory limit controller and OpenTelemetry |
| pulsar-client-api/src/main/java/org/apache/pulsar/client/api/PulsarClientSharedResources.java | Introduces new shared resource types: MemoryLimitController, OpenTelemetry |
| pulsar-client-api/src/main/java/org/apache/pulsar/client/api/OpenTelemetryConfig.java | New public config interface for OpenTelemetry configuration |
| pulsar-client-api/src/main/java/org/apache/pulsar/client/api/MemoryLimitConfig.java | New public config interface for shared memory limit configuration |
| pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PulsarTestClient.java | Updates constructor call for new PulsarClientImpl builder param |
| pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ProducerMemoryLimitTest.java | Adds test validating producers share a memory limit controller across clients |
| pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ConsumerMemoryLimitTest.java | Adds test validating consumers share a memory limit controller across clients |
...lient-api/src/main/java/org/apache/pulsar/client/api/PulsarClientSharedResourcesBuilder.java
Outdated
Show resolved
Hide resolved
...ient/src/main/java/org/apache/pulsar/client/impl/PulsarClientSharedResourcesBuilderImpl.java
Outdated
Show resolved
Hide resolved
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MemoryLimitController.java
Show resolved
Hide resolved
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MemoryLimitController.java
Show resolved
Hide resolved
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/PulsarClientSharedResources.java
Show resolved
Hide resolved
ec00a8f to
1f4a41f
Compare
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.
Fixes #25212
Motivation
#19074 enables sharing of Pulsar client resources across multiple isolated Pulsar client instances, but this solution lacks limiting the total amount of memory across all of the Pulsar client instances. This PR introduces a shared
MemoryLimitControllersolution for PIP-234.Modifications
MemoryLimitControllerto support registering multiple trigger callbacks and deregistering the callback when the client instance gets closed.MemoryLimitControllerinPulsarClientSharedResourcesandPulsarClientSharedResourcesBuilder, then apply the sharedMemoryLimitControllertoPulsarClientImplBuilder.Verifying this change
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: oneby-wang#29