-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[improve][offloaders] Automatically evict Offloaded Ledgers from memory #19783
base: master
Are you sure you want to change the base?
Conversation
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, good work @eolivelli
@eolivelli We should start with a proposal for a new behavior that will introduced to Pulsar, and it also introduced a new configuration. |
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.
We already have invalidateReadHandle
method to invalidate the read handles. Why should we introduce a time-based invalidation for the offloaded read handles? Or, if the change wants to introduce time-based read handle invalidation, why it can't apply to the bookkeeper read handle?
Since we will start the RC version of
So drag this PR to |
The pr had no activity for 30 days, mark with Stale label. |
@eolivelli Is this something for the near term? |
The pr had no activity for 30 days, mark with Stale label. |
@eolivelli @dlg99 Any chance to rebase this PR? |
I have rebased this PR by merging in origin/master to this PR and resolving the conflicts. |
Good point @codelipenghui |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19783 +/- ##
============================================
+ Coverage 73.57% 74.34% +0.77%
- Complexity 32624 34417 +1793
============================================
Files 1877 1944 +67
Lines 139502 147027 +7525
Branches 15299 16201 +902
============================================
+ Hits 102638 109314 +6676
- Misses 28908 29286 +378
- Partials 7956 8427 +471
Flags with carried forward coverage won't be shown. Click here to find out more.
|
void internalTrimLedgers(boolean isTruncate, CompletableFuture<?> promise) { | ||
|
||
internalEvictOffloadedLedgers(); |
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.
I don't see internalEvictOffloadedLedgers
being called anywhere but tests, could you explain how it will be triggered?
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.
@poorbarcode It gets called when internalTrimLedgers
is called.
Motivation
ManagedLedgerImpl retains eagerly a cache of all the BookKeeper ReadHandles.
In case of Offloaded ReadHandler there is kind of a memory leak, as each BlobStoreBackedInputStreamImpl retains a DirectBuffer of 1MB, in the case of a topic with terabytes of data and thousands of ledger this leads to Direct OOM errors if something tries to open all the ledgers
Modifications
Add a new background activity that evicts from memory all the Offloaded ReadHandles and release memory.
The feature is controlled by the new configuration option managedLedgerInactiveOffloadedLedgerEvictionTimeSeconds=600
Unfortunately this fix cannot fully prevent a OODM error because there is no global count and limit of the memory retained by such Handles, it allows to mitigate the problem by releasing automatically unused Ledger Handlers.
The default value, 10 minutes, is very conservative, but it should work with real-world ledgers.
The worst case scenario is a topic with tens of thousands of small ledgers with a consumer that reads from the topic from the beginning, in this case the broker will open the ReadHandlers probably more quickly than the eviction process pace.
Verifying this change
This change added tests.
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: eolivelli#22