In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
The main content of this article is to explain "how to quickly adjust the performance of TomcatJVM parameters to the best". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to quickly adjust the performance of TomcatJVM parameters to the best"!
1. URIEncoding= "UTF-8": sets the character set of Tomcat. We generally do not set this configuration, because we will deal with garbled conversion in specific projects, and it is too rigid to directly modify the character set of Tomcat.
2. MaxThreads= "300": sets the maximum number of concurrency of the current Tomcat. The maximum number of requests configured by Tomcat by default is 150, that is, it can support 150 concurrency at the same time. But in practical application, the maximum number of concurrency has a lot to do with hardware performance and the number of CPU. Better hardware and higher processors will make Tomcat support more concurrency. In general, in actual development, when an application has more than 250 concurrency, the cluster of application servers will be taken into account.
3. MinSpareThreads= "50": sets the number of threads created when the current Tomcat is initialized. The default value is 25.
4. AcceptCount= "250": when the number of simultaneous connections reaches the value set by the maxThreads parameter, you can also receive the number of queued connections, and those who exceed this connection will directly return the rejected connection. Specifies the number of requests that can be put into the processing queue when any number of threads that can be used to process requests are used, and requests beyond this number will not be processed. The default value is 100. In practical application, if you want to increase the concurrency of Tomcat, you should increase the value of acceptCount and maxThreads at the same time.
5. EnableLookups= "false": whether to enable domain name reverse checking is generally set to false to improve processing power. Its value is also true, which is rarely used.
6. MaxKeepAliveRequests= "1": keepalive is not allowed when nginx is dynamically transferred to tomcat,nginx, while keepalive is enabled by default on tomcat and will wait for keepalive's timeout. If not, connectionTimeout is used by default. So you must set the timeout for tomcat and turn off keepalive for tomcat. Otherwise, a large number of socket timewait of tomcat will be generated.
MaxKeepAliveRequests= "1" can prevent tomcat from producing a large number of TIME_WAIT connections, thus avoiding tomcat fake death to some extent.
JVM performance tuning
Tomcat itself runs on JVM, and we can make Tomcat have better performance by adjusting the parameters of JVM. At present, there are two main aspects of tuning for JVM: memory tuning and garbage collection strategy tuning.
I. memory tuning
Find the bin directory under the root directory of Tomcat and set the JAVA_OPTS variable in the catalina.sh file, because the later startup parameters will treat JAVA_OPTS as the startup parameter of JVM. In addition, the memory structure of the Java virtual machine is a bit complex. I believe many people understand it very abstractly. It is mainly composed of heap, stack, method area, garbage collection system and so on. Here is the memory structure diagram I picked from the Internet:
Memory tuning is nothing more than modifying the size of their respective memory space so that the application can be used more reasonably. The following figure shows the parameters I set according to the performance of my machine. Explain the meaning of each parameter in detail:
1.-Xmx512m: sets the maximum available memory size of the heap of the Java virtual machine (in megabytes). The whole heap size = young generation size + old generation size + persistent generation size. The permanent generation usually has a fixed size of 64m. The different distribution of the heap will have a certain impact on the system. Keep objects in the new generation as much as possible, reducing the number of GC in the old age (usually it is slower to recycle in the old age).
In practice, the initial value and the maximum value of the heap are usually set equal, which can reduce the number of garbage collection and space expansion when the program is running, so as to improve the performance of the program.
2.-Xms512m: set the initial memory size of the heap of the Java virtual machine in megabytes (m). This value can be set to the same as-Xmx to avoid JVM redistributing memory after each garbage collection.
3.-Xmn170m: set the memory size of the younger generation in megabytes (m). This value has a great impact on system performance. Sun officially recommends that it be configured as 3max 8 of the entire heap. Generally speaking, after increasing the memory of the younger generation, it will also reduce the size of the older generation.
4.-Xss128k: sets the stack size for each thread. The stack size of each thread after JDK5.0 is 1m, and the previous stack size of each thread is 256K. Adjust the amount of memory required by more applicable threads.
Decreasing this value generates more threads under the same physical memory. However, the operating system still has a limit on the number of threads in a process, which cannot be generated indefinitely, and the experience value is about 3000Murray 5000.
5.-XX:NewRatio=4: set the ratio of the younger generation (including Eden and two Survivor zones) to the older generation (excluding the persistent generation). Set to 4, the ratio of the younger generation to the older generation is 1:4, and the younger generation accounts for 1 prime 5 of the entire stack.
6.-XX:SurvivorRatio=4: set the ratio of Eden area to Survivor area in the young generation. If set to 4, the ratio of two Survivor regions to one Eden region is 2:4, and one Survivor region accounts for 1 Eden 6 of the whole young generation.
7.-XX:MaxPermSize=16m: set the persistent generation size to 16m. As mentioned above, the persistent generation generally has a fixed memory size of 64m.
8.-XX:MaxTenuringThreshold=0: set the maximum age of garbage.
If set to 0, the younger generation will enter the older generation without going through the Survivor area. For more applications of the older generation, it can improve the efficiency.
If you set this value to a large value, the younger generation object will be replicated multiple times in the Survivor area, which can increase the survival time of the younger generation of the object and increase the overview of being recycled in the younger generation.
II. Optimization of garbage collection strategy
Find the bin directory under the Tomcat root directory, and also set the JAVA_OPTS variable in the catalina.sh file. We all know that Java virtual machines have default garbage collection mechanisms, but the efficiency of different garbage collection mechanisms is different, which is why we often adjust the garbage collection policies of Java virtual machines accordingly. Here is also a garbage collection strategy configured through some of my requirements:
The garbage collection strategy of Java virtual machine is generally divided into serial collector, parallel collector and concurrent collector.
Serial Collector:
1.-XX:+UseSerialGC: represents that the garbage collection strategy is a serial collector, that is, a single thread is used in the entire scanning and replication process, which is suitable for applications with single CPU, small new generation space and low pause time requirements. It is the default GC method at client level, mainly in the garbage collection mode before JDK1.5.
Concurrent Collector:
1.-XX:+UseParallelGC: indicates that the garbage collection strategy is a parallel collector (throughput first), that is, the whole scanning and replication process is carried out in a multi-threaded way, which is suitable for applications with multiple CPU and short pause time, and is the default GC method at the server level. This configuration is valid only for the younger generation. This configuration only allows the younger generation to use concurrent collection, while the older generation still uses serial collection.
2.-XX:ParallelGCThreads=4: configure the number of threads in the parallel collector, that is, how many threads perform garbage collection together at the same time. This value is preferably configured equal to the number of processors.
3.-XX:+UseParallelOldGC: configure the old generation garbage collection method to collect in parallel. JDK6.0 supports parallel collection of older generations.
4.-XX:MaxGCPauseMillis=100: set the maximum time for each young generation garbage collection. If this time cannot be met, JVM will automatically adjust the size of the younger generation to meet this value.
5.-XX:+UseAdaptiveSizePolicy: when this option is set, the parallel collector will automatically select the size of the younger generation area and the corresponding Survivor area ratio to achieve the minimum corresponding time or collection frequency specified by the target system. This value is recommended to be turned on when using the parallel collector.
Concurrent Collector:
-XX:+UseConcMarkSweepGC: indicates that the garbage collection strategy is a concurrent collector.
At this point, I believe you have a deeper understanding of "how to quickly adjust the performance of TomcatJVM parameters to the best". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.