3

I am new to heap analysis. We have been using spring boot in our web application. Recently heap usage has become too high. To analyse heap dump with tools like Mat and JProfiler, I am downloading it using actuator as follows:

http://localhost:8080/actuator/heapdump

But each time, I am taking heap dump, heap usage is becoming low. I am suspecting may be GC kicks in all that time. Please rectify if I am wrong. So I am not able to capture the actual scenario. Is there any way to take heap dump without triggering GC ? Or is there anyway like whenever heap usage increases more than say 500 MB, heapdump gets generated.

Joy
  • 4,197
  • 14
  • 61
  • 131

1 Answers1

4

You can have a @Scheduled task to get for you regularly heap usage and generate the 500 MB heapdump. You can use ManagementFactory.getMemoryPoolMXBeans();, it shows the different heap regions and their usage.

To do that externally:

You can use jstat for external monitoring of the heap usage. Wrap it in a script that would analyzse jstat -gc then use jmap to get the heap dump.

Ali Ben Zarrouk
  • 1,891
  • 16
  • 24
  • This requires a code change in the existing package. Is it possible anyway without any code change, I mean like using any external tool or something ? – Joy Apr 05 '19 at 10:03
  • You can use jstat for that then. have a small script running and monitoring your app and then use jmap to get the heap dump. I updated my response with this. – Ali Ben Zarrouk Apr 05 '19 at 11:32
  • What if the application is running in a container? – saran3h May 24 '22 at 14:33
  • @saran3h https://stackoverflow.com/questions/68999346/how-to-capture-application-monitoring-information-from-the-docker-container – Ali Ben Zarrouk May 24 '22 at 17:27