Analysis of startup parameters for tomcat optimization and tomcat optimization parameters

Source: Internet
Author: User
Tags xms jprofiler

Analysis of startup parameters for tomcat optimization and tomcat optimization parameters
Tomcat startup parameters in Linux

Export JAVA_OPTS = "-server-Xms1400M-Xmx1400M-Xss512k-XX: + bytes-XX: + UseBiasedLocking-XX: PermSize = 128 M-XX: MaxPermSize = 256 M-XX: + DisableExplicitGC-XX: MaxTenuringThreshold = 31-XX: + UseConcMarkSweepGC-XX: + UseParNewGC-XX: + CMSParallelRemarkEnabled-XX: + signature-XX: Signature = 128 m-XX: + UseFastAccessorMethods-XX: + UseCMSInitiatingOccupancyOnly-Djava. awt. headless = true"

Tomcat startup parameters in Windows

Set JAVA_OPTS =-server-Xms1400M-Xmx1400M-Xss512k-XX: + AggressiveOpts-XX: + UseBiasedLocking-XX: PermSize = 128 M-XX: MaxPermSize = 256 M-XX: + DisableExplicitGC-XX: MaxTenuringThreshold = 31-XX: + UseConcMarkSweepGC-XX: + UseParNewGC-XX: + CMSParallelRemarkEnabled-XX: + signature-XX: Signature = 128 m-XX: + UseFastAccessorMethods-XX: + UseCMSInitiatingOccupancyOnly-Djava. awt. headless = true

There are a lot of parameters above. Some people may have written that no tomcat startup command has been added with so many parameters. Of course, these parameters are only on my machine and may not be suitable for you, in particular, the value after the parameter needs to be set according to your actual situation.

Parameter description: -Server

For whatever reason, as long as your tomcat is running in the production environment, this parameter must be added to me.

Because tomcat runs in the java-client mode by default, server means that your tomcat runs in the real production mode, this means that your tomcat will have a larger and higher concurrent processing capability and a faster and more advanced JVM garbage collection mechanism when running in server mode, you can get more load and throughput... More... And more...

Y, please remember. Otherwise, this-server will not be added. It is about to beat your ass.

-Xms-Xmx

That is, the JVM memory is set. It is the best practice to set the Xms and Xmx values to the same value. Some people say that Xms is the minimum value and Xmx is the maximum value, which is more user-friendly and scientific. Human nature? Science? Your head.

Consider the following scenario:

As the number of concurrent jobs increases, the memory usage of a system increases gradually, and it cannot rise to the highest point. It starts to fall back. Do not consider this fall as a good thing, when the memory falls back, the price it pays is that the CPU starts to run at high speed for garbage collection. At this time, serious problems may even cause your system to get stuck, which means you are doing well, suddenly, the webpage is several or even dozens of seconds as it is dead, because the JVM is garbage collection.

So we set the two to the same in the beginning, so that Tomcat can maximize the system efficiency by making full use of the parameters at startup, this principle is the same as that of the minpool size and maxpool size in the jdbcconnection pool.

How can I know that my JVM can use the maximum value? Shoot your head? No!

When setting the maximum memory (Xmx) value, open a command line and enter the following command:

Check that the JDK version information is displayed normally. You can use this value. Isn't it true that a 32-bit system can use up to 2 GB of memory? That is: 2048 m. We will try it without defense.

Yes? No! Don't say 2048m. Let's make it a little smaller. How about 1700m?

Hey, I can't even connect to M, let alone 2048m. 2048m is just a theoretical value. In this case, I have several machines here, and some machines-Xmx1800 are okay, some machines can only reach-Xmx1500m.

Therefore, when setting the-Xms and-Xmx values, you must first perform this test. Otherwise, your tomcat will no longer be available in the tomcat startup command line, if you want to fly, you will not be able to fly, but it will become a pitfall cat.

-Xmn

Set the young generation size to 512 MB. Total heap size = size of the young generation + size of the old generation + size of the persistent generation. The permanent generation usually has a fixed size of 64 m. Therefore, increasing the size of the young generation will reduce the size of the old generation. This value has a great impact on the system performance. Sun officially recommends 3/8 of the total heap configuration.

-Xss

Sets the stack size for each thread. This depends on your program to see how much memory a thread will occupy and how many threads may run at the same time. Generally, it is not easy to set the value to more than 1 MB. Otherwise, out ofmemory may easily appear.

-XX: + AggressiveOpts

When this parameter is enabled, your JVM will use the latest optimization technology (if any) when the JDK version is upgraded)

-XX: + UseBiasedLocking

Enable an optimized thread lock. We know that on our appserver, each http request is a thread. If some requests are short and some requests are long, requests will be queued, there may even be thread blocking. This optimized thread lock will automatically optimize the thread processing in your appserver.

-XX: PermSize = 128M-XX: MaxPermSize = 256 M

JVM uses-XX: PermSize to set the non-heap memory initial value. The default value is 1/64 of the physical memory;

When exporting a file with a large amount of data, you must set these two values. Otherwise, a memory overflow error may occur.

Set the maximum non-heap memory size by XX: MaxPermSize. The default value is 1/4 of the physical memory.

Therefore, if the physical memory is 4 GB, one of the 64 points is 64 MB, which is the default PermSize, that is, the initial memory size of the permanent generation;

1/4 is 1024 MB, which is the default MaxPermSize.

-XX: + DisableExplicitGC

Explicit calling "System. gc ()" is not allowed in program code ()". We have seen two excellent projects that manually call System at the end of each DAO operation. gc (), I think it seems like this can solve their out ofmemory problem. The price is that the system response time is greatly reduced, just like I'm talking about Xms, the principles explained in Xmx are the same. Calling GC in this way leads to a great rise and fall in the JVM of the system and poor performance!

-XX: + UseParNewGC

The adoption of multi-thread parallel recovery for the young generation is fast.

-XX: + UseConcMarkSweepGC

CMS gc. This feature is only available in later versions. It uses gc estimation trigger and heap occupation trigger.

We know that the frequent and complex GC will cause the JVM to scale up and down, thus affecting the system efficiency. Therefore, when cms gc is used, we can increase the number of GC times, the response time of each GC is very short. For example, after jprofiler is observed after cms gc is used, GC is triggered many times, and each GC takes only a few milliseconds.

-XX: MaxTenuringThreshold

Set the maximum age of spam. If it is set to 0, the young generation object directly enters the old generation without going through the VOR area. For applications with many older generations, the efficiency can be improved. If this value is set to a greater value, the young generation object will be copied multiple times in the same vor area, which can increase the survival time of the young generation object, increase the probability that the young generation will be recycled.

The setting of this value is an ideal value obtained based on the Local jprofiler monitoring. It cannot be generalized as original.

-XX: + CMSParallelRemarkEnabled

Minimize mark time when UseParNewGC is used

-XX: + UseCMSCompactAtFullCollection

When concurrent gc is used, it prevents memoryfragmention and organizes live objects to reduce memory fragments.

-XX: LargePageSizeInBytes

Page size of Java heap

-XX: + UseFastAccessorMethods

Get, set method into local code

-XX: + UseCMSInitiatingOccupancyOnly

Indicates that the concurrent collector starts collection only after oldgeneration uses the initialization ratio.

-XX: CMSInitiatingOccupancyFraction = 70

CMSInitiatingOccupancyFraction(Xmx-Xmn) * (100-CMSInitiatingOccupancyFraction)/100> = XmnThe promotion failed will not appear. In my application, Xmx is 6000 and Xmn is 512, so Xmx-Xmn is 5488 MB, that is, there are 5488 MB in the old generation, CMSInitiatingOccupancyFraction = 90 indicates that the concurrent garbage collection (CMS) for the old generation starts when the old generation reaches 90%, and 10% of the remaining space is 5488 * 10% = 548 MB, so even if all objects in the Xmn (that is, 512 MB in the young generation) are moved to the old generation, the 548 MB space is enough, so as long as the above formula is full, there will be no promotion failed during garbage collection;

Therefore, the settings of this parameter must be associated with Xmn.

-Djava. awt. headless = true

This parameter is generally used at the end. This full parameter serves this purpose. Sometimes we use some chart tools such as jfreechart in our J2EE project, it is used to output GIF/JPG streams on a web page. In a winodws environment, our app server will not encounter any problems when outputting images, however, in linux/unix environments, an exception is often encountered, which makes your winodws development environment good, but it cannot be displayed in linux/unix, therefore, add this parameter to avoid this situation.

The above configuration can basically achieve:

Faster system response time
JVM recovery speed increases without affecting the system response rate
Maximum JVM memory utilization
Minimize thread congestion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.