-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Fix memory leak when metrics are updated in a thread other than FastThreadLocalThread #24719
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
[fix][broker] Fix memory leak when metrics are updated in a thread other than FastThreadLocalThread #24719
Conversation
lhotari
left a comment
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
|
cc @oneby-wang BTW, the archived open source KoP fixes this issue by remembering the Netty I/O executor everywhere and updating the metrics in that executor. See https://github.com/streamnative/kop/pull/2006/files However, this solution is error-prone because it's easy to miss such pattern. |
...c/main/java/org/apache/pulsar/broker/stats/prometheus/metrics/DataSketchesOpStatsLogger.java
Show resolved
Hide resolved
...ker/src/main/java/org/apache/pulsar/broker/stats/prometheus/metrics/ThreadLocalAccessor.java
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #24719 +/- ##
============================================
+ Coverage 74.17% 74.18% +0.01%
- Complexity 33473 33494 +21
============================================
Files 1895 1896 +1
Lines 148023 148025 +2
Branches 17140 17148 +8
============================================
+ Hits 109790 109813 +23
+ Misses 29471 29456 -15
+ Partials 8762 8756 -6
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…her than FastThreadLocalThread (#24719)
…her than FastThreadLocalThread (apache#24719)
…her than FastThreadLocalThread (#24719)
…her than FastThreadLocalThread (apache#24719) (cherry picked from commit e241b0a)
…her than FastThreadLocalThread (apache#24719) (cherry picked from commit e241b0a)
…her than FastThreadLocalThread (apache#24719)
…her than FastThreadLocalThread (apache#24719) (cherry picked from commit 9715653) (cherry picked from commit cb5a3ab)
…her than FastThreadLocalThread (apache#24719) (cherry picked from commit 9715653) (cherry picked from commit cb5a3ab)
…her than FastThreadLocalThread (apache#24719) (cherry picked from commit 9715653) (cherry picked from commit cb5a3ab)
…her than FastThreadLocalThread (apache#24719) (cherry picked from commit 9715653)
…her than FastThreadLocalThread (apache#24719)
…her than FastThreadLocalThread (apache#24719)
Motivation
See #24714 (comment)
Currently this issue rarely happens because most metrics updates happen in Netty I/O threads when handling requests. However,
DataSketchesOpStatsLoggerandDataSketchesSummaryLoggerare public and can be used by downstream plugins (e.g. protocol handlers).Modifications
recordmethod toLocalDataandThreadLocalAccessorresponsible for updating the metrics.ThreadLocalAccessorTestto verify when the metrics are updated in a normal thread (notFastThreadLocalRunnable), theLocalDataobjects won't be removed from the map inThreadLocalAccessorLocalDatain a non-Netty thread and remove it from the map if it's garbage collected or not alive when iterating the whole map called byrotateLatencyCollection.Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: