Tomcat – JVM Memory Consumption

javamemorytomcat

I am trying to run tomcat on a low memory system (150-256Mb). Even though I start the JVM with -Xmx64m (which should be the default anyway), the process immediately takes up 200Mb+.

I wonder why the JVM needs so much memory itself, or if there is a way of tuning this? Are other JVMs better than the sun one for low memory consumption – and do they work with tomcat?

Best Answer

In addition to the heap (specified by -Xms and -Xmx) you need to include the non heap areas. These include

  • The Perm Gen, which is 64mb on 32bit systems, and 96mb on 64bit systems initially
  • The Code Cache, which is between 20 and 40mb depending on JVM
  • The NIO buffer area (where DirectByteBuffers are drawn from), this is initially 64mb

There is also the working space of the JVM itself which will be a few dozen mb.

You should also be aware of the Sun JVM's auto sizing when using a server class machine. Over time the definition of server class (2Gb memory, more than one core) has suffered some depreciation and now most machines are capable of triggering the -server optimizations. My advice is always to specify the -Xms and -Xmx settings and pass -server unless you can think of a good reason not too.