Tomcat 7: How to Set Initial Heap Size Correctly

Tomcat 7: How to set initial heap size correctly?

You must not use =. Simply use this:

export CATALINA_OPTS="-Xms512M -Xmx1024M"

Can't change tomcat 7 heap size

Set additionally export JAVA_OPTS="-Dcom.sun.management.jmxremote" and use JConsole to inspect the tomcats memory consumption.

TOMCAT 7, Can't change the heap size

Check the setenv.sh in tomcat/bin, according to manual this should be the right place to put those params.

Another option, it depend on your OS tomcat package, may be that config param are overrided in /etc/conf.d/tomcat/ or /etc/tomcat. Just check your init script and your catalina.sh to find where your settings are overrided.

Btw if you run a ps -ef | grep tomcat you should see the full command line with arguments: this may give you an idea of how init script build the command, and so you can investigate where params are set.

How to increase Tomcat Heap memory on windows

Please see detail:

  1. I use apache-tomcat-9.0.14-windows-x64.zip
  2. Sure use right java version
  3. Edit catalina.bat add set JAVA_OPTS=-Xms128m -Xmx1024m after setlocal
  4. Start Tomcat with startup.bat
  5. Check JVM with: start jconsole, select Tomcat, select insecure
  6. See XMS, XMX

If you want start Tomcat9w.exe, you need install service

Want to confirm heap size that tomcat is using

Heap size used by tomcat (as any other java app) is determined by jvm -Xmx param.

So if your tomcat runs as a windows service, you would create environment variable CATALINA_OPTS=-Xms64m -Xmx256m.

Then, look at the file tomcat-install/bin/catalina.sh (.bat) and startup.sh (.bat), and check param JAVA_OPTS
-Xmx1024m or something similar.

Good links:
http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html
http://www.coderanch.com/t/87422/Tomcat/increase-java-heap-size

Invalid initial heap size. Could not create the Java virtual machine

got the correct parameters(JAVA_OPTS) from here. I've set them in setenv.bat.

Difference between setting Heap memory in terms of jvm and Tomcat

Memory settings apply to the JVM, not Tomcat

You can create a separate file %CATALINA_HOME%\bin\setenv.bat or $CATALINA_HOME/bin/setenv.sh and put your environment variables there.

so I'd like to set the JAVA_OPTS variable instead:

set JAVA_OPTS=-Xmx512m

For Xmx:

Specifies the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 and Solaris 8 SPARC platforms and 2000m on Solaris 2.6 and x86 platforms, minus overhead amounts. So, in simple words, you are saying Java to use Maximum of 1024 MB from available memory.

NOTE: there is NO SPACE between -Xmx and 1024m

Resource Link:

  1. How to Change JVM Heap Setting (-Xms -Xmx) of Tomcat – Configure
    setenv.sh file – Run catalina.sh
  2. How to Increase Apache Tomcat HeapSize (JVM Heap) in Eclipse IDE
    (integrated development environment) to Avoid OutOfMemory

UPDATE1: Setting Up Multiple Tomcat Instances

Multiple Tomcat instances are possible to create with the use of the CATALINA_BASE environment variable. Each instance uses a common binary distribution but uses its own conf, webapps, temp, logs and work directories. Each instance also has its own JVM and, thereby, its own memory pool. If you have defined the maximum memory to be 512MB via JAVA_OPTS, each instance will attempt to allocate a maximum of 512MB.

For more details, you can go through this tutorial: Connecting Apache's Web Server to Multiple Instances of Tomcat

Resource Link:

  1. 5 Scenarios and Best Practices for Running Multiple Instances of
    Tomcat or tc Server

Best way to increase heap size in catalina.bat file

If you look in your installation's bin directory you will see catalina.sh or .bat scripts. If you look in these you will see that they run a setenv.sh or setenv.bat script respectively, if it exists, to set environment variables. The relevant environment variables are described in the comments at the top of catalina.sh/bat. To use them create, for example, a file $CATALINA_HOME/bin/setenv.sh with contents

export JAVA_OPTS="-server -Xmx512m"

For Windows you will need, in setenv.bat, something like

set JAVA_OPTS=-server -Xmx768m

Original answer here

After you run startup.bat, you can easily confirm the correct settings have been applied provided you have turned @echo on somewhere in your catatlina.bat file (a good place could be immediately after echo Using CLASSPATH: "%CLASSPATH%"):

Sample Image

Tomcat 6 Heap Size - Is this correct?

Best practice is to put the setting of environment variables in a file named setenv.sh/.bat in the bin folder.

The catalina.sh script has logic to call into this script, if it exists.

The reason why this is recommended is because it makes setting of environment variables needed for your installation portable: you can easily copy setenv.sh to other Tomcat installations, you can upgrade Tomcat to a newer version (which might overwrite catalina.sh) but still have your existing setenv.sh.

An example on how to set the heap size inside setenv.sh:

export JAVA_OPTS='-Xmx784M` 


Related Topics



Leave a reply



Submit