-
Notifications
You must be signed in to change notification settings - Fork 597
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(udf): fix memory leak in Java UDF #13789
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #13789 +/- ##
=======================================
Coverage 68.23% 68.23%
=======================================
Files 1524 1524
Lines 262203 262203
=======================================
+ Hits 178904 178922 +18
+ Misses 83299 83281 -18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Signed-off-by: Runji Wang <[email protected]>
Signed-off-by: Runji Wang <[email protected]>
1d59646
to
c3fce5f
Compare
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.
Amazing!
Which part is the most relevant?
Oh, I think it is:
close() allocators after use (whether they are child allocators or the RootAllocator), either manually or preferably via a try-with-resources statement.
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'm still not 100% sure that create an allocator per call is the intended usage... (e.g., it also mentions that "Because direct memory is expensive to allocate and deallocate, allocators may share direct buffers", so will this have performance influences?) (Besides, IIUC this is just "not deallocating fast enough" instead of "memory leak"? Will it also lead to memory leak if not that much requests?)
But LGTM since it can fix the issue.
According to the document:
I feel that it is encouraged to use child allocators. At least it helped me diagnose and eventually fix the memory leak. As for the performance, I'm also not sure if the overhead is significant. If so, we can remove the child allocator.
Maybe. We have not tested whether a manual GC can reduce the memory consumption. But from a developer's view, it is memory leak. 😇 |
Signed-off-by: Runji Wang <[email protected]>
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
fix #11508
This PR fixes Arrow memory leak in Java UDF. It creates a child allocator for each RPC and uses try-with-resources syntax to ensure the buffer is recycled timely.
With this patch, running the UDF mentioned in #11508 consumes ~800M memory steadily on my Mac.
Reference: https://arrow.apache.org/docs/java/memory.html#arrowbuf
Checklist
./risedev check
(or alias,./risedev c
)Documentation