Apache Tomcat is widely used Web Container in the world. Very big companies run on Apache Tomcat now a days. There are quite a few other alternatives like IBM WebSphere, Geronimo, IIS, etc. but Tomcat is my favorite one too.java
It’s very critical for us to configure all correct parameters while running your application in Production environment or even in development env.web
In this tutorial we will go over steps on how to configure -Xms, -Xmx and -XX:PermSize
value for Tomcat server. Let’s first understand few terms.apache
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.tomcat
NOTE
: there is NO SPACE
between -Xmx and 1024mapp
It’s a size of the heap for the young generation.eclipse
It’s used to set size for Permanent Generation. It is where class files are kept.webapp
Another must read
: Change -Xmx value of Tomcat in Eclipse IDEjvm
Below are the simple steps to change -Xmx / -Xms values or other JVM parameters if you are running Tomcat from command prompt
.ide
Download Apache Tomcat.優化
Go to Apache Tomcat /bin
directory.
[webapp@merch-monkeylbin]$ cat setenv.sh
export CATALINA_OPTS="$CATALINA_OPTS -Xms1024m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx2048m"
<Tomcat Directory>/bin
directory./catalina.sh run
Monitor logfile and you should see your Tomcat started with all your specified parameters in setenv.sh
file.
28-Mar-2019 12:02:02.248 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0022
28-Mar-2019 12:02:02.248 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms1024m
28-Mar-2019 12:02:02.248 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx20248m
You need to create setenv.bat
file with below content:
set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m -server"
and run Tomcat with catalina.bat
優化:
[webapp@merch-monkey conf]$ diff server.xml /mnt/server.xml58c58< maxThreads="700" minSpareThreads="15"/>---> maxThreads="150" minSpareThreads="4"/>116c116< <!--<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />-->---> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />160,161c160<< <!-- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"---> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"163c162< pattern="%h %l %u %t "%r" %s %b" /> -->---> pattern="%h %l %u %t "%r" %s %b" />