Tomcat Tuning Tips

Original Address: https: //mp.weixin.qq.com/s/7_bz3OPoH3x7xkkwkhJhbw

Tomcat tuning this, the interview often asked. Currently Tomcat tuning can be divided into two categories, the current version is explained by the Tomcat 8 :

  Tuning Tomcat itself: the use of static and dynamic separation performance tuning saving Tomcat Tomcat Tomcat thread pool adjusted to modify the connector to disable the operating mode Tomcat AJP connector

  Tuning the JVM: tuning memory Jvm

 

1. Tomcat tuning itself

1.1 uses static and dynamic separation

  If you let Tomcat handle static resources if performance Tomcat will be a lot of wear and tear, so we are generally used: Nginx + Tomcat achieve static and dynamic separation, let Tomcat is only responsible for parsing jsp files, Nginx achieve access to static resources.

 

Tuning thread pools Tomcat 1.2

  Open server.xml tomcat of the Executor configuration, the relevant parameters are as follows.  

<Executor name="tomcatThreadPool" 
        namePrefix="catalina-exec-"
        maxThreads="500" 
        minSpareThreads="20"
        maxIdleTime="60000"/>

  name: to the actuator (thread pool) a name;

  namePrefix: each thread name prefix specified thread pool;

  maxThreads: The maximum number of threads in the thread pool, assuming that the number of requests exceeds 750, this would mean that the property value is set maxThreads 750, it's the best solution is to use "Tomcat cluster." That is, if there is a request 1000, two examples provided Tomcat maxThreads = 500, without providing maxThreads = 1000 in the case of a single Tomcat instance.

  minSpareThreads: the number of threads in the thread pool allows idle (excess threads are killed);

  maxIdLeTime: an idle thread is idle long considered a thread (milliseconds, the configuration here is one minute);

  Other configurations are actually reading official documents is the best, " see reference link ."

 

Tuning Tomcat 1.3 connector Connector   

<Connector executor="tomcatThreadPool" 
        port="8080" 
        protocol="HTTP/1.1"
        connectionTimeout="20000"
        enableLookups="false"
        URIEncoding="UTF-8"
        redirectPort="8443" />

  executor: Specifies the connection used by the actuator (thread pool), Executor 1.2 configured name;

  port: access port;

  protocol: setting protocol processing incoming traffic; the default value is HTTP / 1.1, which uses the switching mechanism automatically be selected based on the non-blocking Java NIO connector or connector-based APR / native.

  enableLookups = false: off DNS resolution, reduce performance loss;

  URIEncoding: character encoding, if not specified, the default is UTF-8

  minProcessors: Create a minimum number of threads when the server starts;

  redirectPort: Redirect port, if the request does not support the non-SSL, it can be removed.

  Other configurations are actually reading official documents is the best, " see reference link ."

 

1.4 operating mode by modifying the Tomcat

  This refers Connector configuration protocol attributes, if not the version that comes with the configuration of Tomcat, you can specify manually.

  BIO: Tomcat8 following versions, the default is to use BIO "blocking IO)" mode. For each request should create a thread for processing, not suitable for high concurrency.

  NIO: Tomcat8 or later, the default is to use NIO mode "non-blocking IO."

  APR: full name of the Apache Portable Runtime, is the preferred embodiment Tomcat production run, if APR APR path or no operating system is not assigned to the default path recognizable Tomcat, the APR model can not start, start NIO automatic switching mode. It is necessary to install the APR and Native, direct start to support APR, APR is the solution to asynchronous IO problems from the operating system level, the nature of the APR is to use JNI technology calls the underlying operating system IO interface, so you need to install in advance dependent on the required upgrade Tomcat static files for processing performance, of course, can also be used static and dynamic separation.

 

1.5 Disable AJP connector 

  AJP stands Apache JServer Protocol, using Nginx + Tomca t framework, so no need AJP protocol, so the AJP connector disabled. Note this is out of the following:

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

 

2. JVM Tuning

  Tomcat is running on the JVM, so JVM tuning is also very necessary. Catalina.sh found in the \ bin file.

   In the previous row cygwin = false add JVM parameters:

  JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8-server -Xms1024m -Xmx1024m -XX:NewSize=512m -XX:MaxNewSize=512m -XXermSize=512m -XX:MaxPermSize=512m -XX:+DisableExplicitGC"

   The purpose of adjusting the size of the heap of garbage collection time is minimized in order to maximize the process requesting clients within a specific time.

 

References:

https://tomcat.apache.org/tomcat-8.0-doc/config/index.html

https://tomcat.apache.org/tomcat-8.0-doc/config/http.html

https://tomcat.apache.org/tomcat-8.0-doc/config/executor.html

 

Guess you like

Origin www.cnblogs.com/huanshilang/p/11582626.html