4

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 is the Process ID). Then I can analyze the dump with VisualVM.

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

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.

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

apangin
  • 92,924
  • 10
  • 193
  • 247
svetli-n
  • 53
  • 1
  • 4
  • I would make sure, a) you are using binary mode b) your heap is as small as possible to start with e.g. minimise heap size an trigger a full GC before taking the dump. – Peter Lawrey Mar 04 '16 at 16:21
  • Hi Peter. I use binary mode, see my edited question and sorry for the confusion. I can not have smaller heap since this is production machine, running with lots of data. – svetli-n Mar 04 '16 at 16:36
  • Taking a heap dump isn't going to be cheap as it will have to stop the JVM to get all the data in a consistent snapshot. – Peter Lawrey Mar 04 '16 at 16:50
  • @apangin - it may be clear *now*, but it wasn't when it was flagged as spam/offensive. – ChrisF Mar 05 '16 at 17:10

1 Answers1

12

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 Files\Java\...\bin\java.exe" core.mdmp

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.

apangin
  • 92,924
  • 10
  • 193
  • 247