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][broker] Implement PIP-430 Pulsar Broker cache improvements by lhotari · Pull Request #24623 · apache/pulsar

Conversation

@lhotari

@lhotari lhotari commented Aug 12, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Fixes #16421
Fixes #24656

Motivation

This is the 2nd implementation PR for "PIP-430: Pulsar Broker cache improvements: refactoring eviction and adding a new cache strategy based on expected read count"

Modifications

  • please see the updated design for PIP-430 which covers the changes in this PR

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Sorry, something went wrong.

Uh oh!

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

All reactions
@lhotari
[improve][broker] Implement PIP-430 Pulsar Broker cache improvements
63ce044
@lhotari lhotari added this to the 4.1.0 milestone Aug 12, 2025
@lhotari lhotari added the ready-to-test label Aug 12, 2025
@github-actions github-actions Bot added PIP doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. labels Aug 12, 2025
@lhotari
Use Awaitility to fix flaky test
acbb052
@codecov-commenter

codecov-commenter commented Aug 13, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.53388% with 287 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.18%. Comparing base (829df71) to head (bbca447).
⚠️ Report is 49 commits behind head on master.

Files with missing lines Patch % Lines
...mledger/impl/ActiveManagedCursorContainerImpl.java 63.61% 122 Missing and 21 partials ⚠️
.../ActiveManagedCursorContainerNavigableSetImpl.java 37.50% 68 Missing and 7 partials ⚠️
...eeper/mledger/impl/ManagedCursorContainerImpl.java 89.43% 13 Missing and 2 partials ⚠️
...mledger/impl/cache/RangeEntryCacheManagerImpl.java 41.66% 12 Missing and 2 partials ⚠️
...per/mledger/impl/cache/RangeCacheRemovalQueue.java 83.33% 5 Missing and 5 partials ⚠️
...keeper/mledger/impl/cache/RangeEntryCacheImpl.java 92.00% 2 Missing and 4 partials ⚠️
...rg/apache/pulsar/broker/service/BrokerService.java 57.14% 6 Missing ⚠️
...kkeeper/mledger/impl/ManagedLedgerFactoryImpl.java 20.00% 4 Missing ⚠️
...ache/pulsar/broker/ManagedLedgerClientFactory.java 57.14% 2 Missing and 1 partial ⚠️
...pache/bookkeeper/mledger/ManagedLedgerFactory.java 0.00% 2 Missing ⚠️
... and 7 more
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #24623      +/-   ##
============================================
- Coverage     74.26%   74.18%   -0.09%     
- Complexity    33213    33377     +164     
============================================
  Files          1885     1893       +8     
  Lines        146953   147722     +769     
  Branches      16928    17080     +152     
============================================
+ Hits         109136   109582     +446     
- Misses        29116    29395     +279     
- Partials       8701     8745      +44     
Flag Coverage Δ
inttests 26.64% <35.11%> (+0.05%) ⬆️
systests 22.74% <32.54%> (+0.11%) ⬆️
unittests 73.67% <70.53%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ache/bookkeeper/mledger/EntryReadCountHandler.java 100.00% <100.00%> (ø)
...apache/bookkeeper/mledger/ManagedLedgerConfig.java 96.57% <100.00%> (+0.01%) ⬆️
...bookkeeper/mledger/ManagedLedgerFactoryConfig.java 100.00% <ø> (ø)
.../org/apache/bookkeeper/mledger/impl/EntryImpl.java 89.39% <100.00%> (+2.47%) ⬆️
...ookkeeper/mledger/impl/ManagedCursorContainer.java 87.50% <ø> (-9.82%) ⬇️
...che/bookkeeper/mledger/impl/ManagedCursorImpl.java 78.09% <100.00%> (+0.08%) ⬆️
...org/apache/bookkeeper/mledger/impl/OpAddEntry.java 77.46% <100.00%> (+0.54%) ⬆️
...he/bookkeeper/mledger/impl/ReadOnlyCursorImpl.java 95.83% <100.00%> (+0.37%) ⬆️
...kkeeper/mledger/impl/cache/EntryCacheDisabled.java 75.55% <100.00%> (ø)
...keeper/mledger/impl/cache/EntryLengthFunction.java 100.00% <100.00%> (ø)
... and 26 more

... and 82 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

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

@lhotari
lhotari marked this pull request as draft August 13, 2025 11:51
lhotari added 11 commits August 13, 2025 15:04
@lhotari
Add updateCursor method that allows lazy ordering of active cursors
70c842c
@lhotari
Improve async-profiler instructions for JMH benchmarks
4087b55
@lhotari
Fix bug in trackedNodeCount
06bc572
@lhotari
Optimize
41da9ee
@lhotari
Use priority queue for pending updates
43c8a61
@lhotari
Update microbench README
78b0f4b
@lhotari
Benchmark with reduced frequency of getNumberOfCursorsAtSamePositionO…
0d43959
…rBefore
@lhotari
Reduce number of forks
28d043e
@lhotari
Skip unnecessary test runs for ManagedCursorContainerImpl
cb83930
@lhotari
Add excludes for JMH result files and profiling results
8799eac
@lhotari
Add cacheEvictionByMarkDeletedPosition and cacheEvictionByExpectedRea…
073a855
…dCount to broker.conf
@lhotari

lhotari commented Aug 14, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

Here's the JMH results for the latest changes. The new getNumberOfCursorsAtSamePositionOrBefore behavior required for cacheEvictionByExpectedReadCount in ActiveManagedCursorContainerImpl is not causing an overhead compared to the previous ManagedCursorContainer tracking for slowest reader position.

Here's a visualization of the results:
JMH Visualizer: ActiveManagedCursorContainerBenchmark

text results

One interesting detail is that ActiveManagedCursorContainerImpl's algorithm would be faster than ManagedCursorContainer's algorithm for tracking the slowest cursor, assuming that most cursors are moving forward (which is the case).

All reactions

Sorry, something went wrong.

Uh oh!

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

@lhotari
lhotari marked this pull request as ready for review August 14, 2025 11:44
lhotari added 8 commits August 18, 2025 11:19
@lhotari
Merge remote-tracking branch 'origin/master' into lh-PIP-430-implemen…
1351eef
…tation
@lhotari
Support partial caching
604ef4e
@lhotari
Add experimental testing case for rolling restarts
140bd1f
@lhotari
Inject delay to connecting to broker, use independent connections to …
722ae97
…broker
@lhotari
Perform different connection delays for producer client and consumer …
fe81d34
…clients
@lhotari
Fix number of restarts, add counter for number of entries that have b…
73ac722
…een read
@lhotari
Show cache hit percentage and cache miss percentage
f911d12
@lhotari
Merge remote-tracking branch 'origin/master' into lh-PIP-430-implemen…
a824151
…tation
@lhotari

lhotari commented Aug 18, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

The recently added "experimental" test case BrokerEntryCacheMultiBrokerTest.testTailingReadsRollingRestart shows the real value of PIP-430 changes. It demonstrates a rolling restart where a producer is producing to a topic and there are 10 connected consumers with unique subscriptions. During the 30 second test period the producer produces as fast as it can and the consumers consume as fast as they can. There are 2 brokers in the cluster and a broker is restarted 3 times during the test period.

The with PIP-430 defaults, Cache hits 98.56%, Cache misses 1.44% :

2025-08-18T19:39:44,894 - INFO  - [main:BrokerEntryCacheMultiBrokerTest] - Produced 21655 and Consumed 206425 messages (across 10 consumers with unique subscriptions) in total. Number of BK reads 74 with 2972 entries. Cache hits 98.56%, Cache misses 1.44%, Number of restarts 3

with cacheEvictionByExpectedReadCount=false, Cache hits 81.66%, Cache misses 18.34%

2025-08-18T19:41:17,119 - INFO  - [main:BrokerEntryCacheMultiBrokerTest] - Produced 20767 and Consumed 197466 messages (across 10 consumers with unique subscriptions) in total. Number of BK reads 848 with 36220 entries. Cache hits 81.66%, Cache misses 18.34%, Number of restarts 3

with cacheEvictionByExpectedReadCount=false and managedLedgerCacheEvictionExtendTTLOfRecentlyAccessed=false, Cache hits 72.97%, Cache misses 27.03%

2025-08-18T19:42:34,214 - INFO  - [main:BrokerEntryCacheMultiBrokerTest] - Produced 20888 and Consumed 198727 messages (across 10 consumers with unique subscriptions) in total. Number of BK reads 1309 with 53708 entries. Cache hits 72.97%, Cache misses 27.03%, Number of restarts 3

The results vary quite a lot and these are values from single runs. However, it demonstrates a significant improvement in reducing the amount of cache misses in rolling restarts when PIP-430 defaults are used.

All reactions

Sorry, something went wrong.

Uh oh!

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

@lhotari
lhotari requested a review from pdolif August 27, 2025 19:41
merlimat
merlimat approved these changes Aug 28, 2025
View reviewed changes

@merlimat merlimat left a comment

Copy link
Copy Markdown
Contributor

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.

The improvements looks super-impressive! Having the micro-benchmarks make a great case.

Only minor comments

Sorry, something went wrong.

Uh oh!

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

lhotari reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread ...ed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeCacheEntryWrapper.java Resolved

Uh oh!

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

Comment thread ...ed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeCacheEntryWrapper.java Resolved

Uh oh!

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

Comment thread pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionPool.java Resolved

Uh oh!

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

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ReferenceCountedEntry.java Resolved

Uh oh!

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

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/Entry.java Resolved

Uh oh!

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

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryReadCountHandlerImpl.java Resolved

Uh oh!

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

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryReadCountHandlerImpl.java Resolved

Uh oh!

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

Comment thread ...edger/src/main/java/org/apache/bookkeeper/mledger/impl/ActiveManagedCursorContainerImpl.java Resolved

Uh oh!

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

lhotari added 3 commits August 28, 2025 10:07
@lhotari
Address review feedback about ReferenceCountedEntry methods that are …
3bde4cd
…part of Entry interface
@lhotari
Remove unused methods from RangeCacheEntryWrapper
3e5e2be
@lhotari
Address review comments in EntryReadCountHandlerImpl
bbca447
@lhotari
lhotari merged commit 490ba0c into apache:master Aug 28, 2025
@Technoboy- Technoboy- assigned lhotari Aug 28, 2025
@lhotari lhotari mentioned this pull request Aug 30, 2025
[improve][build] Add Async Profiler integration for integration tests #24688
Merged
1 of 4 tasks
@lhotari

lhotari commented Sep 3, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

While doing some validation, I noticed that Pulsar has a long time issue that consumers aren't able to keep with producers even when there are available resources unless dispatcherMaxReadBatchSize (and possibly also dispatcherMaxReadSizeBytes) are tuned. The default value for dispatcherMaxReadBatchSize is 100 which seems to be too small. Increasing it to 1000 could help in increasing cache hits and performance.
It's also useful to set preciseDispatcherFlowControl=true while increasing dispatcherMaxReadBatchSize so that unnecessary reads are avoided.

I created #24695 about this.

All reactions

Sorry, something went wrong.

Uh oh!

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

@lhotari lhotari mentioned this pull request Sep 3, 2025
[Enhancement] Improve Pulsar Broker cache defaults to get better out-of-the-box performance #23466
Closed
1 of 2 tasks
KannarFr pushed a commit to CleverCloud/pulsar that referenced this pull request Sep 22, 2025
@lhotari @KannarFr
[improve][broker] Implement PIP-430 Pulsar Broker cache improvements (a…
19738bf
…pache#24623)
walkinggo pushed a commit to walkinggo/pulsar that referenced this pull request Oct 8, 2025
@lhotari @walkinggo
[improve][broker] Implement PIP-430 Pulsar Broker cache improvements (a…
c816a57
…pache#24623)
Demogorgon314 added a commit to Demogorgon314/kop that referenced this pull request Apr 15, 2026
@Demogorgon314
Fix build issue caused by upstream interface changes (streamnative#1447)
d10867d
### Motivation

apache/pulsar#24623:
Updated:
```
public static EntryImpl create(Position position, ByteBuf data)
```
to 
```
public static EntryImpl create(Position position, ByteBuf data, int expectedReadCount)
```

apache/pulsar#24427: 
Updated: 
```
CompletableFuture<Void> updateTopicPoliciesAsync(TopicName topicName, TopicPolicies policies);
```
to
```
    CompletableFuture<Void> updateTopicPoliciesAsync(TopicName topicName,
                                                     boolean isGlobalPolicy,
                                                     boolean skipUpdateWhenTopicPolicyDoesntExist,
                                                     Consumer<TopicPolicies> policyUpdater);
```

### Modifications

Fix build issue caused by upstream interface changes
lhotari added a commit that referenced this pull request Jun 12, 2026
@lhotari
[fix][test][branch-4.0] Backport configurable read/add delays in Puls…
a303ac9
…arMockBookKeeper

Partial cherry-pick of the testmocks changes from
490ba0c ([improve][broker] Implement PIP-430 Pulsar Broker cache
improvements (#24623)), without the JFR read event interceptor parts
which aren't needed on branch-4.0.

Required so that CompactionTest compiles after cherry-picking
ded1e42d352 (#25998), which uses
PulsarMockBookKeeper.setDefaultReadEntriesDelayMillis.
sandeep-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 31, 2026
@lhotari @sandeep-ctds
[fix][test][branch-4.0] Backport configurable read/add delays in Puls…
245aa92
…arMockBookKeeper

Partial cherry-pick of the testmocks changes from
490ba0c ([improve][broker] Implement PIP-430 Pulsar Broker cache
improvements (apache#24623)), without the JFR read event interceptor parts
which aren't needed on branch-4.0.

Required so that CompactionTest compiles after cherry-picking
ded1e42d352 (apache#25998), which uses
PulsarMockBookKeeper.setDefaultReadEntriesDelayMillis.
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Aug 28, 2026
@lhotari @nodece
[fix][test][branch-4.0] Backport configurable read/add delays in Puls…
4b69157
…arMockBookKeeper

Partial cherry-pick of the testmocks changes from
490ba0c ([improve][broker] Implement PIP-430 Pulsar Broker cache
improvements (apache#24623)), without the JFR read event interceptor parts
which aren't needed on branch-4.0.

Required so that CompactionTest compiles after cherry-picking
ded1e42d352 (apache#25998), which uses
PulsarMockBookKeeper.setDefaultReadEntriesDelayMillis.
This was referenced Sep 8, 2026
[Bug] Cached MessageMetadata can outlive the buffer it was parsed from when managedLedgerCacheCopyEntries=true #26493
Closed
[Bug] Transaction log and pending-ack store entries are parsed as MessageMetadata on every cache insert and always fail #26494
Open
@poorbarcode poorbarcode mentioned this pull request Sep 8, 2026
[fix][ml] OOM caused by orphan items in ActiveManagedCursorContainerImpl.pendingPositionUpdates #26506
Closed
10 tasks
dao-jun pushed a commit to ascentstream/pulsar that referenced this pull request Sep 20, 2026
@lhotari @dao-jun
[improve][broker] Implement PIP-430 Pulsar Broker cache improvements (a…
f784137
…pache#24623)

(cherry picked from commit 490ba0c)
@lhotari lhotari mentioned this pull request Sep 30, 2026
[fix][broker] Apply managedLedgerContinueCachingAddedEntriesAfterLastActiveCursorLeavesMillis to managed ledgers #26785
Merged
11 tasks
@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
@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][broker] Implement PIP-430 Pulsar Broker cache improvements (a…
94737e4
…pache#24623)

(cherry picked from commit 490ba0c)
(cherry picked from commit f784137)
This was referenced Oct 24, 2026
PIP-174: Provide new implementation for broker dispatch cache #15954
Closed
[Enhancement] Make cursor caching eligibility logic reactive since reads don't get cached until checkCursorsToCacheEntries has been called #23503
Closed
We need a size limit for cache of single managedLeger #22621
Closed
[Feature] Support ManagedLedger EntryCache cache entires before the slowest cursor #14495
Closed
@merlimat merlimat mentioned this pull request Nov 3, 2026
[improve][test] Speed up ten Broker Group 1 test classes #27322
Merged
10 tasks
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 16, 2026
@lhotari @nodece
[fix][test][branch-4.0] Backport configurable read/add delays in Puls…
8159d53
…arMockBookKeeper

Partial cherry-pick of the testmocks changes from
490ba0c ([improve][broker] Implement PIP-430 Pulsar Broker cache
improvements (apache#24623)), without the JFR read event interceptor parts
which aren't needed on branch-4.0.

Required so that CompactionTest compiles after cherry-picking
ded1e42d352 (apache#25998), which uses
PulsarMockBookKeeper.setDefaultReadEntriesDelayMillis.
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
@pdolif pdolif Awaiting requested review from pdolif

Uh oh!

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

Assignees

@lhotari lhotari

Labels

doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. PIP ready-to-test type/PIP

Projects

None yet

Milestone

4.1.0

Development

Successfully merging this pull request may close these issues.

[Bug] Broker won't immediately cache produced entries when all consumers leave and the first consumer joins Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage

Uh oh!

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

5 participants

@lhotari @codecov-commenter @merlimat @pdolif @coderzc
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.