You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "lhotari (via GitHub)" <gi...@apache.org> on 2026/09/15 15:53:04 UTC

[PR] [feat][ml] Configure and track named Pulsar allocators independently [pulsar]

lhotari opened a new pull request, #26597:
URL: https://github.com/apache/pulsar/pull/26597

   **Depends on #26595. This draft currently includes the changes from #26595 in its diff against `master`.** The additional named-allocator changes are in commit 30782aa545e.
   
   ### Motivation
   
   The managed-ledger entry cache needs its own allocator to retain separate allocation statistics, while benefiting from Pulsar's configurable allocator implementation and OOM handling. This also allows cache copies to use the adaptive allocator introduced in #26595. Efficient cache-owned copies are relevant to the BP-62 batch-read work in #25280, where retaining individual entries can retain larger backing buffers.
   
   ### Modifications
   
   - Introduce a registry that atomically creates one allocator per identifier. `RangeEntryCacheImpl` keeps a private `ALLOCATOR` obtained through `PulsarByteBufAllocator.getOrCreate("ml-cache")`.
   - Resolve each setting from `pulsar.allocator.<id>.<setting>`, then `pulsar.allocator.<setting>`, then its built-in default. Supported settings are `type`, `exit_on_oom`, and `out_of_memory_policy`.
   - Support `pulsar.allocator.default.*` overrides for the default allocator. These overrides do not affect other identifiers. Settings are read when each allocator is first created.
   - Preserve separate cache metrics. Generalize the allocation-statistics snapshot for pooled, unpooled, and adaptive allocators, and resolve broker allocator stats through the registry without creating unknown allocators. Adaptive used-memory statistics report `usedDirectMemory()`; unavailable allocation counts report `-1`.
   - Use Netty's global leak-detection level. Remove support for `pulsar.allocator.leak_detection`; no per-allocator leak-detection setting is introduced.
   - Document named configuration and retain the deprecated `pulsar.allocator.pooled` fallback introduced in #26595.
   
   For example, keep general allocation pooled while enabling adaptive allocation for cache copies:
   
   ```sh
   -Dpulsar.allocator.type=pooled -Dpulsar.allocator.ml-cache.type=adaptive
   ```
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   All 46 scoped tests and `quickCheck` passed locally:
   
   ```sh
   ./gradlew :pulsar-common:test --tests 'org.apache.pulsar.common.allocator.*' \
     :managed-ledger:test --tests 'org.apache.bookkeeper.mledger.impl.cache.RangeEntryCacheImplTest' \
     :pulsar-broker:test --tests 'org.apache.pulsar.broker.stats.AllocatorStatsGeneratorTest' \
     --tests 'org.apache.pulsar.broker.stats.OpenTelemetryManagedLedgerCacheStatsTest' quickCheck
   ```
   
   Tests cover concurrent registration, independent heap/direct metrics for all three allocator types, property inheritance and overrides, OOM policies, global leak detection, cache copy ownership, and broker metrics. Shell syntax and whitespace checks also passed.
   
   ### Does this pull request potentially affect one of the following parts:
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [x] The public API — adds registry APIs, makes the cache allocator private, moves/generalizes the allocation-statistics helper, and removes the Pulsar leak-detection property constant.
   - [ ] The schema
   - [x] The default values of configurations — named cache allocation uses the selected allocator's standard defaults instead of custom zero heap arenas and caching for all threads; leak detection follows Netty's global setting.
   - [ ] The threading model
   - [ ] The binary protocol
   - [x] The REST endpoints — allocator stats look up registered identifiers, retaining the response schema.
   - [ ] The admin CLI options
   - [x] The metrics — retain separate cache statistics and support the selected allocator implementation.
   - [x] Anything that affects deployment — adds named allocator settings and changes leak-detection configuration to Netty's global property.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [feat][ml] Configure and track named Pulsar allocators independently [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #26597:
URL: https://github.com/apache/pulsar/pull/26597#discussion_r4020470026


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheImpl.java:
##########
@@ -49,24 +49,14 @@
 import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl;
 import org.apache.bookkeeper.mledger.intercept.ManagedLedgerInterceptor;
 import org.apache.commons.lang3.tuple.Pair;
+import org.apache.pulsar.common.allocator.PulsarByteBufAllocator;
 import org.apache.pulsar.common.util.FutureUtil;
 
 /**
  * Cache data payload for entries of all ledgers.
  */
 public class RangeEntryCacheImpl implements EntryCache {
-    /**
-     * The Netty allocator used when managedLedgerCacheCopyEntries=true.
-     */
-    public static final PooledByteBufAllocator ALLOCATOR = new PooledByteBufAllocator(true, // preferDirect
-            0, // nHeapArenas,
-            PooledByteBufAllocator.defaultNumDirectArena(), // nDirectArena
-            PooledByteBufAllocator.defaultPageSize(), // pageSize
-            PooledByteBufAllocator.defaultMaxOrder(), // maxOrder
-            PooledByteBufAllocator.defaultSmallCacheSize(), // smallCacheSize
-            PooledByteBufAllocator.defaultNormalCacheSize(), // normalCacheSize,
-            true // Use cache for all threads
-    );
+    private static final ByteBufAllocator ALLOCATOR = PulsarByteBufAllocator.getOrCreate("ml-cache");

Review Comment:
   completed. ready to merge



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [feat][ml] Configure and track named Pulsar allocators independently [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #26597:
URL: https://github.com/apache/pulsar/pull/26597#issuecomment-5684408151

   /pulsarbot rerun


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [feat][ml] Configure and track named Pulsar allocators independently [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat merged PR #26597:
URL: https://github.com/apache/pulsar/pull/26597


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [feat][ml] Configure and track named Pulsar allocators independently [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat commented on code in PR #26597:
URL: https://github.com/apache/pulsar/pull/26597#discussion_r4018328412


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheImpl.java:
##########
@@ -49,24 +49,14 @@
 import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl;
 import org.apache.bookkeeper.mledger.intercept.ManagedLedgerInterceptor;
 import org.apache.commons.lang3.tuple.Pair;
+import org.apache.pulsar.common.allocator.PulsarByteBufAllocator;
 import org.apache.pulsar.common.util.FutureUtil;
 
 /**
  * Cache data payload for entries of all ledgers.
  */
 public class RangeEntryCacheImpl implements EntryCache {
-    /**
-     * The Netty allocator used when managedLedgerCacheCopyEntries=true.
-     */
-    public static final PooledByteBufAllocator ALLOCATOR = new PooledByteBufAllocator(true, // preferDirect
-            0, // nHeapArenas,
-            PooledByteBufAllocator.defaultNumDirectArena(), // nDirectArena
-            PooledByteBufAllocator.defaultPageSize(), // pageSize
-            PooledByteBufAllocator.defaultMaxOrder(), // maxOrder
-            PooledByteBufAllocator.defaultSmallCacheSize(), // smallCacheSize
-            PooledByteBufAllocator.defaultNormalCacheSize(), // normalCacheSize,
-            true // Use cache for all threads
-    );
+    private static final ByteBufAllocator ALLOCATOR = PulsarByteBufAllocator.getOrCreate("ml-cache");

Review Comment:
   Maybe we could use constants for the names



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org