You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Enhancement] PIP-234: Add a solution to share the memory limit controller solution #25212
I searched in the issues and found nothing similar.
Motivation
PIP-234 enables sharing of Pulsar client resources across multiple isolated Pulsar client instances. This was implemented in #24784 and #24790.
The solution lacks limiting the total amount of memory across all of the Pulsar client instances. That would be useful when memory limiting relies on the memory limit controller.
Solution
Modify org.apache.pulsar.client.api.PulsarClientSharedResources interface and implementation to support sharing memory limit controller in the same way as other shared resources are configured without directly referencing implementation instances.
Modify the current MemoryLimitController to support sharing. It would require support for registering multiple trigger callbacks and deregistering the callback when the client instance gets closed.
I'm wondering how to deal with MemoryBufferStats in multiple Pulsar clients? Should they also be shared across multiple clients? I think MemoryBufferStats and MemoryLimitController should have a one-to-one relationship, but I'm not sure if my understanding is correct.
I'm not very familiar with OpenTelemetry, seems all the MemoryBufferStats instances use the same meter name in the master branch? Would that be a problem?
I'm wondering how to deal with MemoryBufferStats in multiple Pulsar clients? Should they also be shared across multiple clients? I think MemoryBufferStats and MemoryLimitController should have a one-to-one relationship, but I'm not sure if my understanding is correct.
Yes, that's correct. org.apache.pulsar.client.impl.PulsarClientSharedResourcesImpl would also have to hold the MemoryBufferStats instance.
I'm not very familiar with OpenTelemetry, seems all the MemoryBufferStats instances use the same meter name in the master branch? Would that be a problem?
I don't think it's a problem, however it would require allowing to pass a org.apache.pulsar.client.impl.metrics.InstrumentProvider instance to the PulsarClientSharedResources builder so that the MemoryBufferStats could be configured appropriately. Right now the situation seems to be that there doesn't seem to be a way to distinguish values when there are multiple Pulsar client instances in a single JVM. I'd assume that there should be a way to configure common Otel attributes in InstrumentProvider, but that's missing. Since it's missing, I think that the concern could be ignored initially and just ensuring that the instrument provider given to PulsarClientSharedResources builder would be used. I think that the instrument provider instance should also be set to the pulsar client builder unless it's already been set.
Oh, I see, it's the developer's duty to pass a different OpenTelemetry instance into PulsarClientSharedResourcesBuilder, just like the ClientBuilderImpl#openTelemetry() method.
Every ClientBuilderImpl and PulsarClientSharedResourcesBuilder should use different OpenTelemetry instances, otherwise they will shared the same global OpenTelemetry instance. Is this understanding correct?
Oh, I see, it's the developer's duty to pass a different OpenTelemetry instance into PulsarClientSharedResourcesBuilder, just like the ClientBuilderImpl#openTelemetry() method.
Yes. The original reason here was to be able to configure the underlying shared MemoryBufferStats instance.
Every ClientBuilderImpl and PulsarClientSharedResourcesBuilder should use different OpenTelemetry instances, otherwise they will shared the same global OpenTelemetry instance. Is this understanding correct?
But, using the same global OpenTelemetry instance across multiple MemoryBufferStats instances seems to cause them to affect each other?
Yes, it would be possible to configure the OpenTelemetry instances differently. However, that's very clumbersome and usually the global instance is shared. The limitation in the org.apache.pulsar.client.impl.metrics.InstrumentProvider class is that there's no way to scope the instance further so that different client instances could produce different type of metrics (let's say with different attributes).
I'm not sure how much of a problem it is to share an instance. Perhaps it's not. I'm sure that the source information would be missing so that you couldn't distinguish the source of a particular metric. It's also possible that there would be some clashes if the same instance is used to create a duplicate metric with the same attributes. However I think that solving that problem could be postponed since it's already possible to manually configure different OpenTelemetry/InstrumentProvider instances for the clients and have them configured in a way where the metrics don't clash.
Activity
oneby-wang commentedon Feb 5, 2026
I'm wondering how to deal with
MemoryBufferStatsin multiple Pulsar clients? Should they also be shared across multiple clients? I thinkMemoryBufferStatsandMemoryLimitControllershould have a one-to-one relationship, but I'm not sure if my understanding is correct.pulsar/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
Lines 289 to 297 in 6d415c6
I'm not very familiar with OpenTelemetry, seems all the
MemoryBufferStatsinstances use the same meter name in the master branch? Would that be a problem?pulsar/pulsar-client/src/main/java/org/apache/pulsar/client/impl/metrics/MemoryBufferStats.java
Lines 26 to 56 in 3dc1fd6
oneby-wang commentedon Feb 5, 2026
If this issue is not assigned, I'd like to contribute.
However, I'm about to go on vacation for about 20 days starting this Saturday. I'll start working on it once I'm back.
If the timeline is ok, I'd be very willing to work on this enhancement.
lhotari commentedon Feb 5, 2026
Yes, that's correct.
org.apache.pulsar.client.impl.PulsarClientSharedResourcesImplwould also have to hold theMemoryBufferStatsinstance.I don't think it's a problem, however it would require allowing to pass a
org.apache.pulsar.client.impl.metrics.InstrumentProviderinstance to the PulsarClientSharedResources builder so that theMemoryBufferStatscould be configured appropriately. Right now the situation seems to be that there doesn't seem to be a way to distinguish values when there are multiple Pulsar client instances in a single JVM. I'd assume that there should be a way to configure common Otel attributes in InstrumentProvider, but that's missing. Since it's missing, I think that the concern could be ignored initially and just ensuring that the instrument provider given to PulsarClientSharedResources builder would be used. I think that the instrument provider instance should also be set to the pulsar client builder unless it's already been set.oneby-wang commentedon Feb 5, 2026
Oh, I see, it's the developer's duty to pass a different
OpenTelemetryinstance intoPulsarClientSharedResourcesBuilder, just like theClientBuilderImpl#openTelemetry()method.pulsar/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
Lines 154 to 158 in 3dc1fd6
Every
ClientBuilderImplandPulsarClientSharedResourcesBuildershould use differentOpenTelemetryinstances, otherwise they will shared the same globalOpenTelemetryinstance. Is this understanding correct?pulsar/pulsar-client/src/main/java/org/apache/pulsar/client/impl/metrics/InstrumentProvider.java
Lines 38 to 52 in 3dc1fd6
But, using the same global
OpenTelemetryinstance across multipleMemoryBufferStatsinstances seems to cause them to affect each other?lhotari commentedon Feb 5, 2026
Yes. The original reason here was to be able to configure the underlying shared MemoryBufferStats instance.
Yes, it would be possible to configure the
OpenTelemetryinstances differently. However, that's very clumbersome and usually the global instance is shared. The limitation in theorg.apache.pulsar.client.impl.metrics.InstrumentProviderclass is that there's no way to scope the instance further so that different client instances could produce different type of metrics (let's say with different attributes).I'm not sure how much of a problem it is to share an instance. Perhaps it's not. I'm sure that the source information would be missing so that you couldn't distinguish the source of a particular metric. It's also possible that there would be some clashes if the same instance is used to create a duplicate metric with the same attributes. However I think that solving that problem could be postponed since it's already possible to manually configure different
OpenTelemetry/InstrumentProviderinstances for the clients and have them configured in a way where the metrics don't clash.