One of our web application was running out of memory recently. Today I finally managed sometime to dig in. First job was to look for a profiler, turns out, there is a cool java profiler named visualvm, it’s free and it now comes with JDK! After configuring it with eclipse and profiling my local tomcat for a while, I realized the easiest thing would be to simply get a thread dump from production and analyze that.
Again, after Googling for a while, I realized that there is a simple utility called jmap that also comes with JDK and let’s you take memory dump. Cool, eh? So here’s the command -
jmap -dump:format=b,file=heap.bin 5796
Here heap.bin is the name of the output file and 5796 is the tomcat process id. It looked pretty simple, all I had to do was run the command, then download the bin file and open it in visualvm. But it never is as simple as it appears, isn’t it? When I ran the command in my production server, I got the following error -
“Not enough storage is available to process this command”
At first it seemed like I don’t have enough storage or memory. But again, after Googling, it turns out you can’t run that command when you Remot Desktop to your production server. The solution was to remote login usign the following command -
mstsc /admin /v:SERVER
I am not sure why, but once I logged in using the /admin parameter, I was able to run the command and take the heap dump that I was after. I’m downloading the file as I write this blog, next step is to find out who’s eating my pie!