Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat Memory Consumption

I am going to install Tomcat on linux with JVM Heap size as 2048m(2GB) to 2304m(2GB+256MB) by setting CATALINA_OPTS="-Xms2048m -Xmx2304m" in cataina.sh file and the Linux OS have 8GB of the RAM so i am making some points , please help with this

  • Should tomcat consume directly 2GB from OS?
  • If no to above ,then how much it should take?
  • If memory is taken by the tomcat is less than 2GB then this 2GB memory allocated by os for this tomcat is only used for this only or some app can use this memory?
  • and finally we are setting the this max and min memory , means OS allocates all that amount of the memory for tomcat?
like image 807
ajduke Avatar asked Feb 23 '23 15:02

ajduke


1 Answers

The JVM will pre-allocate whatever memory you specify for -Xms. So, it will request and allocate 2GB of memory at startup. If it needs more memory later (up to -Xmx), the JVM will request more memory from the OS.

But, do you know you need this much memory? The main driver of memory consumption will be your appication not Tomcat. Simple webapps with a few servlets or JSPs can easily run in less than 32MB of heap. You need to measure your application for performance / load to determine the optimal setting.

A side note - the preferred method for setting JVM parameters is with the JAVA_OPTS setting in setenv.sh, not catalina.sh.

like image 58
AngerClown Avatar answered Mar 02 '23 17:03

AngerClown