Fetching a Heap Dump from a Spring Boot Service

Taking heap dumps of your Java services is an important tool for analyzing problems around your application. With Spring Boot apps running on Kubernetes, a lot of the underlying infrastructure has changed. And so has taking and fetching heap dumps of Spring Boot apps on Kubernetes.

 

A little while ago, while working on a performance analysis, we had the problem that we wanted to look at the heap dump of one of our micro services. We quickly discussed a few possibilities how to do that. But since not every team member of the team was aware of the following method, here’s a short blog post about it.

Spring Boot comes with a dedicated actuator endpoint that makes creating and extracting heap dumps a breeze. But it needs to be exposed first. You need to add the string “heapdump” to the list of exposed endpoints: Spring Boot Actuator: Exposing Endpoints.

Fortunately for us, we had already done this months ago.

Downloading the heap dump is quite simple.

In our AKS cluster, we expose the management API on port 9090, so we had to do the following:

  1. Forward port 9090 from the Pod: kubectl port-forward ms-iiqka-eval-ms-asset-manager-d4c98596-6bgc6 9090

  2. (Optional) Check if the heapdump endpoint is actually enabled: curl localhost:9090/actuator | jq

  3. Create and download the heap dump using curl: curl localhost:9090/actuator/heapdump -o heapdump.hprof

And we’re done.

The heap dump can now be analyzed by using tools like VisualVM.

That's all folks

PS: There’s a threaddump endpoint as well. :wink:

 

Recommended posts