JVM Tuning Summary (vii)-Typical Configuration Example 1

Source: Internet
Author: User
Tags garbage collection thread

The following configurations are primarily intended for the generation of garbage collection algorithms.

Heap Size setting

The setting of the younger generation is critical

There are three limitations to the maximum heap size in the JVM: the data Model (32-BT or 64-bit) of the relevant operating system, the system's available virtual memory limits, and the system's available physical memory limits. 32-bit system, generally limited to 1.5g~2g;64 for the operating system for unlimited memory. In Windows Server 2003 system, 3.5G physical memory, JDK5.0 under test, maximum can be set to 1478m.

Typical settings:

java-xmx3550m-xms3550m-xmn2g–xss128k

-xmx3550m: Set JVM maximum available memory to 3550M.

-xms3550m: Set the JVM to drive memory to 3550m. This value can be set to be the same as-xmx to avoid the JVM reallocating memory after each garbage collection completes.

-XMN2G: Set the young generation size to 2G. Entire Heap size = young generation size + old age size + persistent generation size. The permanent generation generally has a fixed size of 64m, so increasing the younger generation will decrease the size of the older generation. This value has a significant impact on system performance, and Sun officially recommends configuring the 3/8 of the entire heap.

-xss128k: Sets the stack size for each thread. JDK5.0 the size of each thread stack is 1M, before each thread stack size is 256K. The memory size required for the more applied thread is adjusted. In the same physical memory, reducing this value can generate more threads. However, the operating system on a process of the number of threads is still limited, can not be unlimited generation, experience value in 3000~5000 around.

Java-xmx3550m-xms3550m-xss128k-xx:newratio=4-xx:survivorratio=4-xx:maxpermsize=16m-xx:maxtenuringthreshold=0

-xx:newratio=4: Set the ratio of the young generation (including Eden and two survivor) to the older generation (excluding persistent generations). Set to 4, the ratio of the younger generation to the older generation was 1:4, and the young generation accounted for 1/5 of the entire stack.

-xx:survivorratio=4: Set the ratio of the size of Eden area and survivor area in the younger generation. Set to 4, the ratio of two survivor to an Eden area was 2:4, and a survivor area accounted for 1/6 of the entire young generation.

-XX:MAXPERMSIZE=16M: Sets the persistent generation size to 16m.

-xx:maxtenuringthreshold=0: Set the maximum age of rubbish. If set to 0, then the younger generation objects do not go through the survivor area, directly into the old generation. More applications for older generations can improve efficiency. If this value is set to a larger value, the young generation object will replicate multiple times in the Survivor area, which can increase the lifetime of the object in the younger generation and increase the introduction of the recovery in the younger generation.

Collector Selection

The JVM gives three choices: a serial collector, a parallel collector, and a concurrent collector, but the serial collector applies only to small amounts of data, so the choice is primarily for parallel collectors and concurrent collectors. By default, JDK5.0 used to use serial collectors, and if you want to use a different collector, you need to add the appropriate parameters at startup. After JDK5.0, the JVM is judged according to the current system configuration.

Parallel collector with throughput priority

As mentioned above, the parallel collector is mainly for the purpose of reaching a certain throughput, which is suitable for science and technology and background processing.

Typical configuration:

Java-xmx3800m-xms3800m-xmn2g-xss128k-xx:+useparallelgc-xx:parallelgcthreads=20

-XX:+USEPARALLELGC: Select the garbage collector as the parallel collector. This configuration is valid only for young generations. That is, the younger generation uses concurrent collection under the above configuration, while the older generation still uses serial collection.

-XX:PARALLELGCTHREADS=20: The number of threads that configure the parallel collector, that is, how many threads are garbage collected together. This value is best configured to be equal to the number of processors.

Java-xmx3550m-xms3550m-xmn2g-xss128k-xx:+useparallelgc-xx:parallelgcthreads=20-xx:+useparalleloldgc

-XX:+USEPARALLELOLDGC: Configure the old Generation garbage collection method for parallel collection. JDK6.0 supports parallel collection of older generations.

java-xmx3550m-xms3550m-xmn2g-xss128k-xx:+useparallelgc-xx:maxgcpausemillis=100

-XX:MAXGCPAUSEMILLIS=100: Sets the maximum time for each young generation of garbage collection, and if this time is not met, the JVM automatically adjusts the young generation size to meet this value.

N Java-xmx3550m-xms3550m-xmn2g-xss128k-xx:+useparallelgc-xx:maxgcpausemillis=100-xx:+useadaptivesizepolicy

-xx:+useadaptivesizepolicy: When this option is set, the parallel collector automatically chooses the young generation size and the corresponding survivor ratio to reach the minimum appropriate time for the target system or the collection frequency, which is recommended when using a parallel collector.

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.