TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Lessons from debugging a tricky direct memory leak

30 点作者 SerCe超过 1 年前

6 条评论

brancz超过 1 年前
I’m incredibly confused why profiling wasn’t even mentioned in this post.<p>I would highly recommend anyone troubleshooting something like this to do continuous profiling and the root cause of this type of problem becomes painfully obvious within seconds.<p>(Disclaimer I founded a company in this space, and we recently open sources a library for rust to do this: <a href="https:&#x2F;&#x2F;www.polarsignals.com&#x2F;blog&#x2F;posts&#x2F;2023&#x2F;12&#x2F;20&#x2F;rust-memory-profiling" rel="nofollow">https:&#x2F;&#x2F;www.polarsignals.com&#x2F;blog&#x2F;posts&#x2F;2023&#x2F;12&#x2F;20&#x2F;rust-memo...</a>)
评论 #38785890 未加载
benrow超过 1 年前
We ran into a problem where we blew the direct memory limit recently.<p>To trace the problem, I added a breakpoint on ByteBuffer.allocateDirect() - this is how DM is normally allocated. But rather than suspending the process, we set it to print the stacktrace and continue.<p>This gave us handy output of possible causes. Focusing on the cases which were called from our own code (likely to be the root cause), we found a call to Files.readAllBytes() - which immediately sounds suspicious to cause a memory leak. Indeed this was the culprit, and explained why the problem was sporadic and hard to reproduce (there is some kind of per-thread caching behaviour of direct memory I never did understand properly).<p>Incidentally, Files.readAllBytes() uses direct memory because it uses an area of memory which both the OS can access (onto which to read the file contents) and which also Java can access (for the application code, rather than copying to the heap, which could be inefficient for large files).<p>Fortunately, this &quot;by inspection&quot; approach got us to the answer.<p>Others have stated profiling would work well. We&#x27;d have needed a local reproduction of the issue, which wasn&#x27;t available at the time (could not reproduce without realistic workloads). Otherwise we could have used our SaaS APM software which runs in deployed envs, but that takes a sampling approach and doesn&#x27;t really dig deep enough for this kind of stuff.
TheNewAndy超过 1 年前
If you have a memory leak, then take a process that has been leaking for a while and look at its memory. Just pole a few places at random and statistically you should quickly find what is leaking. I am pressure this would have cut down a lot of the investigation needed in this story (though it is always easy to say this kind of thing after the biug has been found)
SerCe超过 1 年前
I stumbled upon this article in the latest edition of the &#x27;Java Performance Tuning Newsletter&#x27;. Relatively recently, I also published a blog article [1] diving into all aspects of JVM memory, including native memory profiling.<p>[1]: <a href="https:&#x2F;&#x2F;serce.me&#x2F;posts&#x2F;01-02-2023-jvm-field-guide-memory" rel="nofollow">https:&#x2F;&#x2F;serce.me&#x2F;posts&#x2F;01-02-2023-jvm-field-guide-memory</a>.
qingcharles超过 1 年前
Off topic, but I use Pinterest extensively for work and pleasure. It has all sorts of funny bugs that don&#x27;t really interfere with using it. One of them is content that looks spicy, but is grandfathered in so it doesn&#x27;t get flagged. If you try to repin it on your board their AI gets upset. These two tricky images caught it out this week for me:<p><a href="https:&#x2F;&#x2F;imgur.com&#x2F;a&#x2F;9Pew0EE" rel="nofollow">https:&#x2F;&#x2F;imgur.com&#x2F;a&#x2F;9Pew0EE</a>
Thaxll超过 1 年前
Java flight recorder wouldn&#x27;t help here?
评论 #38785868 未加载