Optimize Tomcat configuration (memory concurrency caching etc.) in detail

  • 2020-06-23 02:30:19
  • OfStack

Tomcat has many aspects. I introduce optimization methods in memory, concurrency, caching, and so on.

1.Tomcat memory optimization

Tomcat memory tuning is primarily an optimization of the tomcat startup parameter, which can be set in the ES10en.sh startup script.

JAVA_OPTS parameter specification

server server edition with jdk enabled;
-ES26en java Virtual machine initialization minimum memory;
-Xmx java Maximum memory available for virtual machine;
-ES32en: The PermSize memory is permanently reserved
-XX:MaxPermSize maximum permanently reserved area of memory

Server parameter configuration

At present, the maximum 2G can be added to server memory 1, so the following configuration can be adopted:

JAVA_OPTS='-Xms1024m -Xmx2048m -XX: PermSize=256M -XX:MaxNewSize=256m -XX:MaxPermSize=256m'

After the configuration is completed, restart Tomcat and check if the configuration is in effect by using the following command:

First check the Tomcat process number:
sudo lsof -i:9027
We can see that the Tomcat process number is 12222.

Check to see if the configuration is in effect:
sudo jmap? heap 12222
We can see that parameters like MaxHeapSize are in effect.

2.Tomcat concurrent optimization

1.Tomcat connection parameters

In the Tomcat configuration file server. xml


  <Connector port="9027"
  protocol="HTTP/1.1"
  maxHttpHeaderSize="8192"
  minProcessors="100"
  maxProcessors="1000"
  acceptCount="1000"
  redirectPort="8443"
  disableUploadTimeout="true"/>

2. Adjust the concurrent processing capability of connector connector

1 > Parameters that

Maximum number of threads requested by maxThreads customers
Number of socket threads created when minSpareThreads is initialized
The maximum number of free socket threads for the maxSpareThreads Tomcat connector
If enableLookups is set to true, it supports domain name resolution and can resolve ip address to hostname
redirectPort forwards customer requests to redirectPort port based on SSL where secure channel-based is required
Maximum number of acceptAccount listening port queue, when full, the client request will be rejected (not less than maxSpareThreads)
connectionTimeout connection timeout
Minimum number of threads to process when minProcessors server is created
The maxProcessors server has a maximum number of simultaneous processing threads
URIEncoding URL series 1 code

2 > Example configuration in Tomcat


  <Connector port="9027"
  protocol="HTTP/1.1"
  maxHttpHeaderSize="8192"
  maxThreads="1000"
  minSpareThreads="100"
  maxSpareThreads="1000"
  minProcessors="100"
  maxProcessors="1000"
  enableLookups="false"
  URIEncoding="utf-8"
  acceptCount="1000"
  redirectPort="8443"
  disableUploadTimeout="true"/>

3.Tomcat cache optimization

1 > Parameters that

c ompression turns on compression
compressionMinSize enables compressed output content size, which defaults to 2KB
compressableMimeType compression type
connectionTimeout defines the timeout for establishing a customer connection. If -1, there is no limit on the time for establishing a customer connection

2 > Example configuration in Tomcat


  <Connector port="9027"
  protocol="HTTP/1.1"
  maxHttpHeaderSize="8192"
  maxThreads="1000"
  minSpareThreads="100"
  maxSpareThreads="1000"
  minProcessors="100"
  maxProcessors="1000"
  enableLookups="false"
  compression="on"
  compressionMinSize="2048"
  compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
  connectionTimeout="20000"
  URIEncoding="utf-8"
  acceptCount="1000"
  redirectPort="8443"
  disableUploadTimeout="true"/>

4. Reference configuration

1 > Legacy configuration

The server has been configured as follows by reference network, please share it:


  <Connector port="9027"
  protocol="HTTP/1.1"
  maxHttpHeaderSize="8192"
  maxThreads="1000"
  minSpareThreads="25"
  maxSpareThreads="75"
  enableLookups="false"
  compression="on"
  compressionMinSize="2048"
  compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
  connectionTimeout="20000"
  URIEncoding="utf-8"
  acceptCount="200"
  redirectPort="8443"
  disableUploadTimeout="true" />

It turned out that there was a performance bottleneck at over 3 million page views.

2 > The changed configuration


  <Connector port="9027"
  protocol="HTTP/1.1"
  maxHttpHeaderSize="8192"
  maxThreads="1000"
  minSpareThreads="100"
  maxSpareThreads="1000"
  minProcessors="100"
  maxProcessors="1000"
  enableLookups="false"
  compression="on"
  compressionMinSize="2048"
  compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
  connectionTimeout="20000"
  URIEncoding="utf-8"
  acceptCount="1000"
  redirectPort="8443"
  disableUploadTimeout="true"/>

conclusion

That's the end of this article on optimizing the Tomcat configuration (memory, concurrency, caching, etc.), and I hope it helps. Interested friends can continue to read: Talk about Tomcat3 operation mode, Tomcat JMX service method introduction, jsp- to solve the file upload after the restart of Tomcat file automatic deletion problem, if there is any deficiency, welcome to leave a message, this site will be timely reply and correction, to provide you with a better article for reference.


Related articles: