JVM heap dump configuration process

in Tutorials with 7 comments

In the process of development, testing and even production environment, sometimes outofmemoryerror is encountered, and Java heap overflows, which indicates that the program has serious problems. We need to find the cause of the memory problem. There are generally two situations:

1. Memory leak, the object has died, and can not be recycled automatically by garbage collector. The solution can be determined by finding out the location and cause of the leaked code;
2. Memory overflow, all objects in memory must still be alive, which indicates that Java heap allocation space is insufficient. Check the heap setting size (- Xmx and - XMS), and check whether the object life cycle is too long and the holding state time is too long.

In the above example, the idea of handling the problem of elastdump in the Java system is to handle the problem of the system.

Main process:

1. Using the dump service of jdump
2. Use mat to view the heap dump

The following is a record of the pit filling.

Tool installation

We mainly need jmap and mat (memory analysis tool).

1. Install jmap

 sudo yum install java-1.8.0-openjdk-devel-debug

Jmap is one of the JDK toolchains. In general, for services that need to be debugged, the tool chain under the version is used for the JDK running. For example, for Java 1.8.0, JDK uses 1.8.0.

2. Install mat

Mat (memory analyzer tool), a memory analysis tool based on eclipse, is a fast and functional Java heap analysis tool. It can help us find memory leaks and reduce memory consumption. Use memory analysis tools to analyze many objects, quickly calculate the occupied size of objects in memory, and see who prevented the garbage collector's recycling work, and visually view the objects that may cause this result through reports.

Select different versions according to their desktop systems, and configure the Java SDK bin environment variable to directly open and use.

Download address: https://www.eclipse.org/mat/downloads.php

Use configuration

1. Get the main process number of ES

 [gz-52-175 ~] $systemctl status elasticsearch @ elasticsearch.service-elasticsearch) load: loaded (/ usr / lib / SYSTEMd / system / system / elasticsearch.service; enabled; vendor preset: disabled) 
 drop-in: drop in: / etc / system / system / system / elasticsearch.service.d.d └ - override.conf active: active: active: active: active: active: activeactiveactiveactiveactive: activeactiveactive: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: active: (running) since 3, 2018-09-12 02:08:28 CST; Doc: http: / / www.elastic. Co main PID: 144765 (Java) 
 cggroup: / system. SLIC / elasticsearch. Service └ - 144765 / bin / bin / Java - xms31g - xmx31g - XX: + usecommarksweepggc - XX: cmsinitiatingoccupancyffraction = 80 - XX: + usecminitiatingo..., September 12 02:08:08: 28 gz-52-52-52-52-52-52-52-52-52-52-52-52-52-52-52-52-52-28 gz-52-52-52-52-52-52-52-52-52-52-52-september 12 02:08:28: 28: 28 gz-52-52-52-52-52-52-52-52-52-52 175 SYSTEMd [1]: started elasticsearch systemd[1]: Starting Elasticsearch...

among Main PID: 144765 (java) Of one hundred and forty-four thousand seven hundred and sixty-five It's the main process number.

2. Using jmap

Output in binary form, output to /tmp/es-heap.hprof In which {PID} Change to one hundred and forty-four thousand seven hundred and sixty-five Can

 sudo -u elasticsearch jmap -dump:format=b,file=/tmp/es-heap.hprof {PID}

output hprof During the process, the current ES process will be kept in the blocked state and no longer work. Please be sure to do it at a time that does not affect the business, such as late at night.

Hypothetical output hprof For the size of 22G, it usually takes 1 minute.

3. Using mat

If es-heap.hprof If it is larger than 1G, the configuration of mat needs to be changed to support reading large files. The configuration of mat in different environments is different. The following is an example of eclipse memory analyzer of windows x64 version.

In the software directory, open edit MemoryAnalyzer.ini , found -Xmx1024M , change to hprof Size is OK, for example hprof 20g, changed to -Xmx20g Save after modification. Restart mat and it will open smoothly hprof

Here is an example:

 1536808996702-987d8062-7557-43c6-ba39-adbd53c6585f-image.png
 1536809034914-27efa6a2-0780-43d9-a918-b0b503568930-image.png
 1536809078369-2ccfb6e3-cb9c-45d4-9305-212e97614391-image.png

Then you can have a pleasant look at the various situations of heap.

This is the tutorial.

Responses
  1. wwaf

    Otaku de benefits: https://6wll.com

    Reply
    1. jing zhang
      @wwaf

      Zazasa, yes

      Reply
      1. aa
        @jing zhang

        Ha ha aaaaaaaa

        Reply
  2. The template is very nice

    Reply
  3. xlj

    The magic board

    Reply
    1. one hundred and twenty-two thousand two hundred and twenty-two
      @xlj

      Master law third party

      Reply
  4. Is the main building to do the back end or the front end?

    Reply