Skip to content

Fix Memory Leak In Netty Recycler of Bookie Client#4609

Merged
merlimat merged 4 commits into
apache:masterfrom
TakaHiR07:fix_change_recycler_to_static
Jun 2, 2025
Merged

Fix Memory Leak In Netty Recycler of Bookie Client#4609
merlimat merged 4 commits into
apache:masterfrom
TakaHiR07:fix_change_recycler_to_static

Conversation

@TakaHiR07

@TakaHiR07 TakaHiR07 commented May 30, 2025

Copy link
Copy Markdown
Contributor

Main Issue: apache/pulsar#24355

Motivation

There is a huge memory leak risk in netty recycler of bookie client . The issue and analysis is show here: apache/pulsar#24355

Changes

Currently, each perChannelBookieClient has its own recycler.

After modification, All the completionKey and completionValue is no longer the inner class of perChannelBookieClient, and each perChannelBookieClient would share the same recycler.

Notice: after the modification, it is more important to set a appropriate io.netty.recycler.maxCapacityPerThread config. Because I have tested that if we do not rely on cache object, the read and write performance would have a little decrease. Since all the channel in bkClient share the same recycler, we should make the config = add entry qps * add entry average latency.

import org.apache.bookkeeper.net.BookieId;
import org.slf4j.MDC;

class AddCompletion extends CompletionValue implements BookkeeperInternalCallbacks.WriteCallback {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Refactoring by pulling the classes out masks the actual fix here. Can you, for this fix, leave the refactoring aside?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually, after reviewing a bit, it kind of makes sense to split the classes in this PR, since it forces all classes to be static.

import org.apache.bookkeeper.net.BookieId;
import org.slf4j.MDC;

class AddCompletion extends CompletionValue implements BookkeeperInternalCallbacks.WriteCallback {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually, after reviewing a bit, it kind of makes sense to split the classes in this PR, since it forces all classes to be static.

Comment thread bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/AddCompletion.java Outdated
@merlimat merlimat merged commit 87ca7f3 into apache:master Jun 2, 2025
23 checks passed
merlimat added a commit that referenced this pull request Jun 2, 2025
* make recycler static to avoid OOM problem

* Fixed missing license headers

* Fixed checkstyle

* More checkstyle

---------

Co-authored-by: fanjianye <fanjianye@bigo.sg>
Co-authored-by: Matteo Merli <mmerli@apache.org>
priyanshu-ctds pushed a commit to datastax/bookkeeper that referenced this pull request Jul 11, 2025
* make recycler static to avoid OOM problem

* Fixed missing license headers

* Fixed checkstyle

* More checkstyle

---------

Co-authored-by: fanjianye <fanjianye@bigo.sg>
Co-authored-by: Matteo Merli <mmerli@apache.org>
(cherry picked from commit 137cc94)
sandeep-ctds pushed a commit to datastax/bookkeeper that referenced this pull request Jul 22, 2025
* make recycler static to avoid OOM problem

* Fixed missing license headers

* Fixed checkstyle

* More checkstyle

---------

Co-authored-by: fanjianye <fanjianye@bigo.sg>
Co-authored-by: Matteo Merli <mmerli@apache.org>
(cherry picked from commit 137cc94)
@hangc0276 hangc0276 added this to the 4.18.0 milestone May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants