GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [improve][ml] Use adaptive allocation for managed ledger cache copies by lhotari · Pull Request #26603 · apache/pulsar

Conversation

@lhotari

@lhotari lhotari commented Sep 16, 2026

Copy link
Copy Markdown
Member

Motivation

Follow up on #25280 and #26597. Batch reads are now enabled by default, and their entries must be copied into cache-owned buffers even when managedLedgerCacheCopyEntries=false: retaining one entry must not retain the entire BookKeeper response frame. This makes the ml-cache allocator relevant to the default storage-read path.

Use Netty's adaptive allocator as the built-in default for these copies. The expected workload is many small entries with similar sizes. The rationale is reduced fragmentation waste under that assumption:

  • Netty 4.2.18's small-allocation path separates sizes into magazine groups and reuses individually freed slots within a chunk. Entries that remain cached therefore do not prevent reuse of the slots released by other entries. Its size classes include power-of-two payload sizes plus room for headers, limiting rounding waste for that common pattern. Small-entry chunks start at 128 KiB rather than the pooled allocator's usual 4 MiB chunk size. See the pinned implementation.
  • The size-class design discussion specifically addresses small, plentiful allocations and long-lived small buffers preventing reuse of large chunks. It introduced reusable free-list slots to reduce that fragmentation. This is a closer match to cache insertion and eviction than the original histogram-only adaptive design.
  • Netty's allocator documentation describes adaptive's smaller chunks and makes it the Netty 4.2 default. The chunk-sizing discussion also explains how page-aligned chunk sizing reduces fragmentation pressure on the system allocator.

This is a workload-based default choice, not a measured performance claim. Size-class rounding, partially occupied chunks, and allocator caches still consume memory; adaptive does not guarantee lower RSS for every size distribution or eviction pattern. No benchmarks were run.

managedLedgerCacheCopyEntries=false retains the incoming buffer; it does not imply unpooled allocation. The previous cache-copy allocator was pooled. This change preserves APIs, data formats, and explicit allocator settings, while deliberately changing allocation and memory-retention behavior when no allocator type is configured. Operators can retain the previous policy with -Dpulsar.allocator.ml-cache.type=pooled.

Modifications

  • Default only the ml-cache allocator to adaptive. General and other named allocators remain pooled. Preserve named overrides, global type fallback, and legacy pulsar.allocator.pooled settings.
  • Document the default, its scope, and the explicit pooled override in pulsar_env.sh.
  • Fix the remaining batch-read mock size-limit bug: a zero-length first entry must count as an accepted entry, so [0, 2048] with a 1024-byte limit is split into separate rounds.
  • Add allocator default/override tests, end-to-end batch splitting coverage with caching enabled/disabled and open/reopened ledgers, and the missing BookKeeper batch-disabled configuration case.
  • Strengthen the batch-cache regression to use slices of one shared response, evict all but one cached entry, and verify that the response is released while the cached entry remains readable.

The merged batch-read change already corrected mandatory cache copying, unsupported-bookie fallback documentation, and ensemble/quorum configuration names. Its protocol guard now checks the actual BookKeeper client configuration; this follow-up retains that design.

Verifying this change

  • ./gradlew quickCheck (license headers and main/test checkstyle).
  • Targeted PulsarByteBufAllocatorTest, PulsarByteBufAllocatorTypeTest, ManagedLedgerBatchReadTest, RangeEntryCacheImplTest, and ManagedLedgerTest.testBatchReadRequiresClientSupport, with retries disabled.
  • Verified the new regressions fail for the intended reasons when mandatory batch-cache copying and the zero-length mock fix are temporarily removed; restored both afterward.

Does this pull request potentially affect one of the following parts:

The built-in managed-ledger cache allocator changes from pooled to adaptive. Explicit allocator settings retain their precedence.

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lhotari added 2 commits September 16, 2026 16:08
@lhotari
[improve][ml] Use adaptive allocation for managed ledger cache copies
002d497
Preserve explicit allocator overrides and cover shared batch buffer release. Fix mock batch size splitting after an empty entry and cover the BookKeeper batch-read kill switch.

Assisted-by: Codex
@lhotari
[fix][ml] Clarify managed cache allocator default
cd10388
Keep the pooled fallback explicit for the default allocator while using adaptive for ml-cache when no allocator type is configured.

Assisted-by: Codex
@lhotari
lhotari requested review from Technoboy-, dao-jun, david-streamlio, merlimat and nodece September 16, 2026 14:01
@lhotari lhotari mentioned this pull request Sep 16, 2026
[improve][broker] Avoid redundant read-completion executor handoffs lhotari/pulsar#277
Closed
2 of 11 tasks
merlimat
merlimat approved these changes Sep 16, 2026
View reviewed changes
dao-jun
dao-jun approved these changes Sep 16, 2026
View reviewed changes

@dao-jun dao-jun left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lhotari
lhotari merged commit 0677be2 into apache:master Sep 16, 2026
44 checks passed

Uh oh!

There was an error while loading. Please reload this page.

dao-jun pushed a commit to ascentstream/pulsar that referenced this pull request Sep 20, 2026
@lhotari @dao-jun
[improve][ml] Use adaptive allocation for managed ledger cache copies (…
9e9d0c7
…apache#26603)

(cherry picked from commit 0677be2)
dao-jun pushed a commit to ascentstream/pulsar that referenced this pull request Sep 20, 2026
@lhotari @dao-jun
[improve][ml] Use adaptive allocation for managed ledger cache copies (…
54e637e
…apache#26603)

(cherry picked from commit 0677be2)
dao-jun pushed a commit to ascentstream/pulsar that referenced this pull request Sep 20, 2026
@lhotari @dao-jun
[improve][ml] Use adaptive allocation for managed ledger cache copies (…
4f184f2
…apache#26603)

(cherry picked from commit 0677be2)
@lhotari lhotari added this to the 5.0.0 milestone Oct 1, 2026
@dao-jun dao-jun mentioned this pull request Oct 4, 2026
[feat][ml] Port batch read and managed-ledger cache improvements (PIP-430) on BK 4.17.4.1 ascentstream/pulsar#105
Closed
Radiancebobo pushed a commit to Radiancebobo/pulsar that referenced this pull request Oct 8, 2026
@lhotari hechengbo
[improve][ml] Use adaptive allocation for managed ledger cache copies (…
3caeed7
…apache#26603)
@nodece nodece mentioned this pull request Oct 13, 2026
[feat][ml] Port batch read and managed-ledger cache improvements (PIP-430) on BK 4.17.4.1 (ml-only subset) ascentstream/pulsar#106
Closed
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Oct 13, 2026
@lhotari @nodece
[improve][ml] Use adaptive allocation for managed ledger cache copies (…
5ac3fa9
…apache#26603)

(cherry picked from commit 0677be2)
(cherry picked from commit 4f184f2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@merlimat merlimat merlimat approved these changes
@dao-jun dao-jun dao-jun approved these changes
@nodece nodece Awaiting requested review from nodece
@Technoboy- Technoboy- Awaiting requested review from Technoboy-
@david-streamlio david-streamlio Awaiting requested review from david-streamlio

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

5.0.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@lhotari @merlimat @dao-jun
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.