Tomcat

How to Change JVM Heap Setting (-Xms -Xmx) of Tomcat – Configure setenv.sh file – Run catalina.sh

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:PermSizevalue for Tomcat server. Let’s first understand few terms.apache

-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.tomcat

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

-Xmn

It’s a size of the heap for the young generation.eclipse

-XX:PermSize

It’s used to set size for Permanent Generation. It is where class files are kept.webapp

Another must readChange -Xmx value of Tomcat in Eclipse IDEjvm

Let’s get started:

Below are the simple steps to change -Xmx / -Xms values or other JVM parameters if you are running Tomcat from command prompt.ide

Step-1

Download Apache Tomcat.優化

Step-2

Go to Apache Tomcat /bin directory.

 

[webapp@merch-monkeylbin]$ cat setenv.sh
export CATALINA_OPTS="$CATALINA_OPTS -Xms1024m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx2048m"

Step-4

  1. Go to command prompt.
  2. Go to <Tomcat Directory>/bin directory
  3. Execute command: ./catalina.sh run

Step-5

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

Command for Windows Environment:

You need to create setenv.bat file with below content:

set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m -server"

and run Tomcat with catalina.bat

 
關閉 localhost_access_log日誌
修改在tomcat的安裝目錄conf文件夾下 server.xml裏配置,將 AccessLogValve註釋掉:

優化:

[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 &quot;%r&quot; %s %b" /> -->---> pattern="%h %l %u %t &quot;%r&quot; %s %b" />

相關文章
相關標籤/搜索