tomcat Performance Optimization of Performance Overview

  • 2020-06-07 05:41:55
  • OfStack

1. Increase JVM heap memory size

1) JVM generally does not call the garbage collector, so the server can focus more on processing web requests and asking for them to be completed as soon as possible.

2) Change file (ES8en.sh)


 JAVA_OPTS= " -Djava.awt.headless=true -Dfile.encoding=UTF-8
    -server -Xms1024m -Xmx1024m
    -XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=512m
    -XX:MaxPermSize=512m -XX:+DisableExplicitGC " 
  -Xms  �   Specifies the stack memory that is initialized when initialized 
  -Xmx  �   Specifies the maximum stack memory 

2. Fix JRE memory leak

1) The latest VERSION of tomcat, 6.0.26 and above, resolves this error as it includes a listener to handle memory leaks from JRE and PermGen.

2) Change server. xml


 <Listener className= " org.apache.catalina.core.JreMemoryLeakPreventionListener "  />

3. Thread pool Settings

The value of maxThreads should be based on the size of the traffic,

If the value is too low, there will not be enough threads to process all the requests, and the request will enter the wait state, which will only be processed after 1 processing thread is released.

If you set it too large, the startup of Tomcat will take more time. So it's up to us to set maxThreads to the correct value.

The parameters associated with the maximum number of connections are maxProcessors and acceptCount. If you want to increase the number of concurrent connections, you should increase both parameters.


<Connector port= " 9027 " 
  protocol= " HTTP/1.1 " 
  maxHttpHeaderSize= " 8192 " 
  maxThreads= " 1000 " 
  minSpareThreads= " 100 " 
  maxSpareThreads= " 1000 " 
  minProcessors= " 100 "         Minimum number of free connection threads to improve system processing performance 
  maxProcessors= " 1000 "        Maximum number of connection threads, that is, the maximum number of concurrent requests 
  enableLookups= " false "        Whether to reverse check domain name, the value is:  true  or  false  . To improve processing power, set to  false
  compression= " on " 
  compressionMinSize= " 2048 " 
  compressableMimeType= " text/html,text/xml,text/javascript,text/css,text/plain " 
  connectionTimeout= " 20000 "      Network connection timeout, in milliseconds. Set to  0  Indicates that it will never time out. Usually can be set to 30000  Milliseconds. 
  URIEncoding= " utf-8 " 
  acceptCount= " 1000 "         The maximum number of connections allowed should be greater than or equal to  maxProcessors
  redirectPort= " 8443 " 
  disableUploadTimeout= " true " />

4. The compression


compression= " on " 
compressionMinSize= " 2048 " 

Compression occurs when the file size is 2048bytes or greater

5. Database performance tuning

Tomcat performance degrades while waiting for database queries to be executed

Ensure that all database connections are closed properly.

Maximum number of free (maxIdle), maximum number of connections (maxActive), maximum connection wait time (maxWait) attribute value.

6. Other options

Enable the browser's cache so that static content stored in the webapps folder can be read faster, giving a big boost to overall performance
The Tomcat server should be restarted automatically every time it is started

HTTPS requests are generally slower than HTTP requests. If you want better security, we'll go with HTTPS even if it's a bit slower

Set TOMCAT to enable GZIP compression


compression= " on "   Turn on compression 
compressionMinSize= " 50 "   Compressed output content size, default 2KB
noCompressionUserAgents= " gozilla, traviata "   Compression is not enabled for the following browsers 
compressableMimeType= " text/html,text/xml,text/javascript,text/css,text/plain "Which resource types need to be compressed 

Related articles: