如何以最少的停机时间在 Windows 中进行堆转储? [英] How to take a heap dump in windows with minimum downtime?

查看:18
本文介绍了如何以最少的停机时间在 Windows 中进行堆转储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚为什么 Elasticsearch 节点上的 JVM 堆使用率始终保持在 80% 以上.为了做到这一点,我通过运行进行堆转储

I want to figure out why JVM heap usage on Elasticsearch node is staying consistently above 80%. In order to do this, I take a heap dump by running

jmap.exe -heap:format=b 5348

(5348 是进程 ID).然后我可以使用 VisualVM 分析转储.

(5348 is the Process ID). Then I can analyze the dump with VisualVM.

问题是jmap在进行转储时暂停了JVM,所以节点基本离线5分钟左右.

The problem is that jmap pauses the JVM while taking the dump, so the node is basically offline for around 5 minutes.

这篇文章依赖于在 Linux 上使用 gdb 进行核心转储的方法.我已经尝试过 WinDbg,它创建了一个核心转储,但我无法在 VisualVM 中使用它.

This article suggests a faster approach that relies on taking coredump with gdb on Linux. I already tried WinDbg, which created a core dump, but I couldn't use it in VisualVM.

Windows 是否有类似的方法?如何在几秒钟而不是几分钟内完成堆转储?

Is there a similar approach for Windows? How one can take heap dumps in seconds, not minutes?

推荐答案

在您通过 WinDbg 获取 coredump 之后,您需要通过运行来从中提取堆转储

After you've taken the coredump by WinDbg, you need to extract the heap dump from it by running

jmap -heap:format=b "C:Program FilesJava...injava.exe" core.mdmp

这可以离线完成;不需要与正在运行的 Java 进程交互.然后你就可以在 VisualVM 中打开生成的 heap.bin.

This could be done offline; no interaction with running Java process needed. Then you will be able to open the generated heap.bin in VisualVM.

或者,您可以采用类直方图.它的生成速度比完整堆转储快.

Alternatively you may take the class histogram. It is produced a way faster than full heap dump.

jmap -histo <PID>

它向您显示其实例占用堆中最多空间的类的列表.这些信息通常足以让您了解丢失的记忆在哪里.

It shows you the list of classes whose instances occupy the most space in the heap. This information is often enough to get the idea of where's the memory lost.

这篇关于如何以最少的停机时间在 Windows 中进行堆转储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆