How to tune the JVM-optimize Java Virtual machines (Daquan + instances)

Source: Internet
Author: User

Heap Settings
  • -xmx3550m: Set JVM maximum heap memory to 3550M.
  • -xms3550m: Set the JVM initial heap memory to 3550M. This value can be set to the same as-xmx to avoid the JVM reallocating memory after each garbage collection completes.
  • -xss128k: Sets the stack size for each thread . After JDK5.0, each thread stack size is 1M, before each thread stack size is 256K. Adjustments should be made based on the size of memory required by the application's thread. In the same physical memory, reducing this value can generate more threads. However, the operating system of the number of threads within a process is still limited, can not be generated indefinitely, the empirical value of 3000~5000 around.
  • -XMN2G: Sets the heap memory young generation size to 2G. entire heap memory size = Young generation size + old generation size + persistent generation size . The permanent average fixed size is 64m, so increasing the younger generation will reduce the size of older generations. This value has a large impact on system performance, and Sun's official recommendation is 3/8 for the entire heap.
  • -xx:permsize=256m: Sets the heap memory to a persistent generation with an initial value of 256M. (It looks like the initialization parameters of the IDE such as Eclipse)
  • -xx:maxnewsize=size: The newly generated object can occupy the maximum memory value.
  • -XX:MAXPERMSIZE=512M: Sets the maximum value for the persistent generation to 512M.
  • -xx:newratio=4: Sets the ratio of older generations of heap memory (including Eden and two survivor) to the old generation of heap memories (except for persistent generations) . Set to 4, the ratio of the younger generation to the older generation is 1:4.
  • -xx:survivorratio=4: Sets the ratio of the Eden area to the survivor area in the young generation of heap memory . Set to 4, two survivor zones (default for 2 survivor in the JVM heap memory) and one Eden area are 2:4, and one survivor area represents 1/6 of the entire young generation.
  • -xx:maxtenuringthreshold=7: Indicates that an object is placed in the old generation if it is moved 7 times in the rescue space (survivor area) without being recycled.
    • If set to 0, then the young generation of objects do not go through the survivor area, directly into the old generation, for older generations of more applications, this can improve efficiency.
    • If this value is set to a larger value, the younger generation objects are duplicated multiple times in the Survivor area, which increases the chance that the object will survive in the younger generation, increasing the probability that the object is recycled in the younger generation.
Collector Selection

The JVM gives three choices: the serial collector, the parallel collector, the concurrent collector, but the serial collector is only available for small amounts of data, so the choice here is primarily for the parallel collector and the concurrency collector.

By default, JDK5.0 used a serial collector before, and if you want to use a different collector, you need to add the appropriate parameters at startup. After JDK5.0, the JVM is intelligently judged based on the current system configuration.

Serial collector
    • -XX:+USESERIALGC: Setting up the serial collector
Parallel collector (throughput first)
  • -XX:+USEPARALLELGC: Select the garbage collector as the parallel collector. This configuration is only valid for younger generations. In this configuration, the younger generation uses concurrent collection, while the older generation still uses serial collection.
  • -XX:PARALLELGCTHREADS=20: Configures the number of threads for a parallel collector, that is, how many threads are garbage collected together. This value is best configured to be equal to the number of processors.
  • -XX:+USEPARALLELOLDGC: Configure the old Generation garbage collection method for parallel collection. JDK6.0 supports parallel collection of older generations.
  • -XX:MAXGCPAUSEMILLIS=100: Sets the maximum time (in milliseconds) for each young generation of garbage collection, and if this time is not met, the JVM automatically adjusts the younger generation size to meet this value.
  • -xx:+useadaptivesizepolicy: When this option is set, the parallel collector automatically selects the size of the younger generation and the corresponding Survivor area scale to achieve the minimum response time, or collection frequency, as specified by the target system.
    • This parameter is recommended to be turned on when using the parallel collector.
Concurrent Collector (response time first)
  • -XX:+USEPARNEWGC: Set Young on behalf of concurrent collection. Can be used concurrently with CMS collection. JDK5.0 above, the JVM will set itself according to the system configuration, so it is no longer necessary to set this value.
    • CMS, full name concurrent low Pause Collector, is a new GC algorithm introduced by the jdk1.4 later version, which has been further improved in Jdk5 and JDK6, and its main fit scenario is that the need for response time is greater than the throughput requirements. The ability to tolerate garbage collection threads and application threads to share processor resources, and to apply applications where there are more long-life-cycle objects. CMS is used to recover tenured generation, that is, the recovery of older generations, the goal is to minimize the application of the pause time, reduce the probability of FULLGC occurrence, the use and application thread concurrent garbage collection thread token to clear the old generation.
  • -XX:+USECONCMARKSWEEPGC: Set old age on behalf of concurrent collection. After configuring this in the test, the configuration of the-xx:newratio=4 is invalidated. Therefore, at this time the younger generation size is best set with-XMN.
  • -xx:cmsfullgcsbeforecompaction=: Because the concurrent collector does not compress and defragment the memory space, it can produce "fragmentation" after a period of time, which makes the operation less efficient. This parameter sets the memory space to be compressed and organized after running the secondary FULLGC.
  • -xx:+usecmscompactatfullcollection: Turn on compression for older generations. Performance may be affected, but memory fragmentation can be eliminated.
  • -xx:+cmsincrementalmode: Set to incremental collection mode. Generally applies to single CPU situations.
  • -XX:CMSINITIATINGOCCUPANCYFRACTION=70: The old generation of space to 70% when the implementation of the CMS, to ensure that the elderly have enough space to accept from the young generation of objects.

Note: If you use throughput collector and concurrent low pause collector These two garbage collectors, you need to have the appropriate high memory size to prepare for multithreading.

Other
  • -XX:+SCAVENGEBEFOREFULLGC: The New generation GC takes precedence over full GC execution.
  • -XX:-DISABLEEXPLICITGC: Disable calling System.GC (), but the JVM's GC is still valid.
  • -xx:+maxfdlimit: Maximizes the limit of the number of file descriptors.
  • -xx:+usethreadpriorities: Enables the local thread priority API, even if java.lang.Thread.setPriority() It is in effect, is not valid.
  • -xx:softreflrupolicymspermb=0: The "soft reference" object can survive the last 0 milliseconds (default is 1 seconds) after being accessed.
  • -xx:targetsurvivorratio=90: Allow 90% of survivor space to be occupied (default is 50%). Increase the usage of survivor-more than you would try garbage collection.
Ancillary information
  • -xx:-citime: Print consumption at JIT compile time
  • -xx:errorfile=./hs_err_pid.log: Save the error log or data to the specified file
  • -xx:-extendeddtraceprobes: Opening a Solaris-specific dtrace probe
  • -xx:heapdumppath=./java_pid.hprof: Specifies the path or file name when the heap information is exported
  • -xx:-heapdumponoutofmemoryerror: Export the information in this heap when a memory overflow is first encountered
  • -xx:onerror= ";" : Run custom command after fatal error
  • -xx:onoutofmemoryerror= ";" : Execute custom command when memory overflow is first encountered
  • -xx:-P Rintclasshistogram: The bar information of the print class instance after Ctrl-break, same as Jmap-histo function
  • -XX:-P rintconcurrentlocks: Information about printing concurrent locks after ctrl-break, same as jstack-l function
  • -xx:-P rintcommandlineflags: Print markup that appears on the command line
  • -xx:-P rintcompilation: Printing related information When a method is compiled
  • -xx:-P RINTGC: Print related information per GC
  • -xx:-P RINTGC Details: Print detailed information each time GC
  • -xx:-P rintgctimestamps: print timestamp for each GC
  • -XX:-TRACECLASSLOADING: Tracking load information for a class
  • -XX:-TRACECLASSLOADINGPREORDER: Tracking load information for all referenced classes
  • -XX:-TRACECLASSRESOLUTION: Tracking Constant pool
  • -XX:-TRACECLASSUNLOADING: Tracking uninstall information for a class
  • -XX:-TRACELOADERCONSTRAINTS: Tracking information about class loader constraints
JVM Service Tuning Combat

Server: 8 Cup, 8G Mem

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

Tuning Solution:

  • -xmx5g: Sets the maximum available memory for the JVM to 5G.
  • -xms5g: Set the JVM initial memory to 5G. This value can be set to 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 memory size = Young generation size + old generation size + persistent generation size . The permanent average fixed size is 64m, so increasing the younger generation will reduce the size of older generations. This value has a large impact on system performance, and Sun's official recommendation is 3/8 for the entire heap.
  • -XX:+USEPARNEWGC: Set Young on behalf of the parallel collection. Can be used concurrently with CMS collection. JDK5.0 above, the JVM will set itself according to the system configuration, so it is no longer necessary to set this value.
  • -xx:parallelgcthreads=8: Configures the number of threads for a parallel collector, that is, how many threads are garbage collected together. This value is best configured to be equal to the number of processors.
  • -xx:survivorratio=6: Sets the ratio of the size of Eden and survivor in the younger generation. With experience set to 6, the ratio of two survivor to one Eden area is 2:6, and one survivor area represents 1/8 of the entire young generation.
  • -XX:MAXTENURINGTHRESHOLD=30: Sets the maximum age of garbage (number of times). If set to 0, then the young generation object does not go through the survivor area directly into the old generation. For older generations of more applications, can improve efficiency. If this value is set to a larger value, the younger generation objects are duplicated multiple times in the Survivor area, which increases the survival time of the object's younger generations, increasing the probability of being recycled in the younger generation. A setting of 30 means that an object is placed in the old age if it is moved 30 times in the survivor space and has not been recycled.
  • -XX:+USECONCMARKSWEEPGC: Set old age on behalf of concurrent collection. After testing the configuration parameter, the parameter-xx:newratio=4 is invalidated, so it is best to use the-XMN setting for the younger generation, so this parameter is not recommended.
reference-generation of JVM heap memory

The heap memory of the virtual machine is divided into three generations: young Generation, Old Generation, and persistent (Permanent Generation). The persistent generation primarily stores the class information of the Java class, which is not much related to the Java objects that the garbage collector collects. Therefore, the division between the younger generation and the old generation is more significant to the garbage collection.

Young Generation

All newly generated objects are first placed in the younger generation. The goal of the young generation is to collect as quickly as possible those objects with short life cycles. The young generation is divided into three districts. One Eden area, two survivor districts (in general).

Most objects are generated in the Eden area. When the Eden Zone is full, the surviving objects will be copied to the Survivor area (one of two), and when a survivor area is full, the surviving objects of this area will be copied to another survivor area, and when another survivor area is full, Objects that were copied from a survivor area and survived at this time will be copied "old age area (tenured)".

It is important to note that the two survivor zones are symmetrical and have no relationship, so the same survivor area may also have objects copied from the Eden area and copied from another survivor area. , but copied to the old quarter of the past only one survivor area (relative) came over the object. Moreover, there is always an empty survivor area. In special cases, depending on the program's needs, the survivor area can be configured to multiple (more than two), which increases the age of the object in the younger generation and reduces the likelihood of being placed in the old generation.

Old Generation

Objects that survived after N (configurable) garbage collection in the younger generation will be placed in the old age generation. Therefore, it can be considered that older generations are storing objects with longer life cycles.

Durable Generation

Used to store static data, such as Java Class, Method, and so on. Persistent generations have no significant impact on garbage collection, but some applications may dynamically generate or invoke some classes, such as Hibernate, in which case a large, persistent generation space is required to hold the dynamically increasing types during these runs. The persistent generation size is set by-xx:maxpermsize=.

How to tune the JVM-optimize Java Virtual machines (Daquan + instances)

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.