In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to optimize the important parameters of Tomcat. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.
The most common change is to modify the port of the server, which is the Connector section in server.xml. Typical examples are shown below:
In fact, most of the optimizations are also within the Connector tag, from ports, concurrency to threads, which can be configured here.
I. 3 parameters to get concurrent configuration
As a Web container that can undertake high concurrent Internet requests, the first impact is of course the impact of massive requests. Fortunately Tomcat supports NIO, and we can adjust the thread count and concurrency configuration to get it to perform optimally.
maxThreads --The maximum number of threads tomcat receives client requests, that is, the number of tasks processed at the same time. Its default size is 200. Generally speaking, in highly concurrent I/O intensive applications, this value is set to about 1000.
maxConnections This parameter is the maximum number of connections tomcat can accept at any one time. For Java's blocking BIO, the default is the value of maxthreads; if custom Executor executors are used in BIO mode, the default will be the value of maxThreads in the executor. For Java's new NIO mode, maxConnections defaults to 10000, so we generally leave this parameter unchanged.
acceptCount --Maximum number of queues that can be accepted when the number of threads reaches the value set above. Beyond this value, the request is rejected. I usually set it to the same size as maxThreads.
A brief description of the relationship between the above three parameters:
Number of connections the system can maintain
maxConnections+acceptCount, the difference is that connections in maxConnections can be scheduled; connections in acceptCount can only wait for queuing
Number of requests the system can handle
maxThreads The size of threads, the number of threads that can actually work.
Happiness Index: maxThreads > maxConnections > acceptCount.
Some articles are still full of maxProcessors and minProcessors. However, these two parameters have been deprecated since Tomcat5 and completely disappeared since Tomcat 6.
It can only be said that these articles you see may really be published by operations that do not understand technology.
Represented by 8, the specific configuration parameters can be seen in:
https://tomcat.apache.org/tomcat-8.0-doc/config/http.html II. Thread Configuration
In terms of concurrency configuration, you can see that we only have minSpareThreads, but we don't have maxSpareThreads. This is because, starting with Tomcat 6, the Executor node has been added, and this parameter is no longer useful.
Since a thread is a pool, it is configured to meet all the characteristics of the pool.
Reference:
https://tomcat.apache.org/tomcat-8.0-doc/config/executor.html
namePrefix --The name prefix of each new thread
maxThreads --Maximum number of threads in the thread pool
minSpareThreads --Number of threads that are always active
maxIdleTime -idle time of threads, after which they are destroyed
threadPriority --Priority of threads in the thread pool, default is 5
Third, fix JVM configuration
Tomcat is a Java application, so JVM configuration also affects its performance. The most important configuration parameters are as follows.
2.1 Memory area size
The first thing to adjust is the size of each partition, but this also has to be divided into garbage collectors, we just look at some global parameters.
-XX:+UseG1GC First, specify the garbage collector used by the JVM. Try not to rely on default values to ensure that you explicitly specify one.
-Xmx sets the maximum heap size, typically 2/3 of the operating system size.
-Xms sets the initial value of the heap, usually set to the same size as Xmx to avoid dynamic expansion.
-Xmn young generation size, default Cenozoic generation accounts for 1/3 of heap size. High concurrency and fast death scenarios can appropriately enlarge this area. Half, or more, is fine. But in G1, you don't have to set this value anymore, it adjusts automatically.
-XX:MaxMetaspaceSize limits the size of metaspace, generally 256M is enough. This is usually set to the same initial size **-XX:MetaspaceSize**.
-XX:MaxDirectMemorySize Sets the maximum value for direct memory, limiting memory requested through DirectByteBuffer.
-XX:ReservedCodeCacheSize Sets the size of the code repository after JIT compilation. If you observe that this value has a limit, you can adjust it appropriately. It is generally sufficient.
-Xss sets the stack size, the default is 1M, which is enough.
2.2 memory tuning
-XX:+AlwaysPreTouch initializes all the memory specified in the parameters when it starts. The startup time will be slower, but the running speed will increase.
-XX:SurvivorRatio defaults to 8. Represents the proportion of Eden and Survivor.
-XX:MaxTenuringThreshold This value defaults to 6 under CMS and 15 under G1. This value is related to the object elevation we mentioned earlier, and the effect of the change will be obvious. The age distribution of the object can be printed using **-XX:+PrintTenuringDistribution**. If the size of the later generations is always the same, it proves that the object after a certain age can always be promoted to the older generation, and the promotion threshold can be set small.
PretenureSizeThreshold objects above a certain size will be allocated directly in the old age. However, this parameter is not used much.
2.3 Garbage collector optimization
G1 Garbage Collector
-XX:MaxGCPauseMillis sets a target pause time that G1 will try to achieve.
-XX:G1HeapRegionSize Sets the heap size. This value is a power of 2, not too large, not too small. If you are not sure how to set it, leave it at default.
-XX:InitiatingHeapOccupancyPercent When the total heap memory usage reaches a certain percentage (45% by default), the concurrent marking phase is started.
-XX: Number of threads used by ConcGCThreads concurrent garbage collector. Default values vary depending on the platform on which the JVM runs. No changes are recommended.
IV. Other important configurations
Let's look at a few more important parameters configured in Connector.
enableLookups --Calls request, getRemoteHost() to perform a DNS query to return the host name of the remote host or, if set to false, the IP address directly. This is based on demand.
URIEncoding --Character encoding used to decode URLs, not specified Default ISO-8859-1
connectionTimeout --timeout for the connection in milliseconds
redirectPort --Specifies the port number to redirect after receiving an SSL transport request while the server is processing http requests
About "Tomcat important parameters how to optimize" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.