0

I'm doing Memory management analysis for my Java web application,

Before starting my tomcat the free memory was around 595 MB, Once I started the server the free memory goes to 151 MB. When I took the Heap dump, the objects were occupying 262 MB.

So will tomcat alone take remaining 181 MB?

Another question is, I ran Load Test with 500 Users. The free memory goes to 8MB, When I took heap dump here, It was around 265MB. So free space 151 MB is reduced to 8MB, What could be reason

Selvakumar P
  • 305
  • 2
  • 8
  • 16

3 Answers3

1

Firstly, read and understand http://www.linuxatemyram.com/ for why "free" memory numbers are much lower than you might think.

Secondly, Java allocates its entire heap upfront from the operating system, although it doesn't touch or dirty the pages until they're actually used. This gives you top output like:

 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND         
9521 pjc       17   0 1288m 524m  25m S  0.0 13.3  58:31.92 java

That's me running Eclipse; the VIRT column shows that Java probably has a 1024Mb maximum heap size; on top of that are libraries and memory allocated for storing the compiled Java. However only 524Mb of that is currently in RAM.

Your heap dump is the best guide to how much memory your application is using - provided that's after it's done a garbage collection.

Jeff Ferland
  • 20,547
  • 2
  • 62
  • 85
pjc50
  • 1,720
  • 10
  • 12
0

The operating system is smart, not stupid. It understands that free memory is wasted memory, no better than memory that isn't in the system at all. It's not like if your 4GB machine uses only 3GB today, you can use 5GB tomorrow.

So it keeps stuff that it might be able to use in RAM. If it later is able to use it, that's a performance win. Amazingly, if it later isn't able to use it, it's still a performance win because if it had made it free, it would just have to make it in use again. (That would require two operations, whereas switching it directly from one use to another is just one operation.)

Modern operating systems only make a small amount of memory free and only when they have no choice.

David Schwartz
  • 31,449
  • 2
  • 55
  • 84
0

Use psi-probe to actually see what goes on in the JVM. Or VisualVM, but psi-probe is more accessible.

pyroscope
  • 231
  • 1
  • 3