Chapter 9 JVM tuning recommendations and chapter 9 JVM tuning recommendations

Source: Internet
Author: User
Tags xms

Chapter 9 JVM tuning recommendations and chapter 9 JVM tuning recommendations

Note: This article mainly references distributed Java applications: basics and practices

 

1. JVM optimization is mainly about memory optimization, mainly in two aspects:

  • Size of each generation
  • Garbage Collector Selection

2. Size of each generation

  • Common Adjustment Parameters
    • -Xmx
    • -Xms
    • -Xmn
    • -XX: Invalid vorratio
    • -XX: MaxTenuringThreshold
    • -XX: PermSize
    • -XX: MaxPermSize
  • Principles
    • -Xmx =-Xms: prevents frequent heap memory adjustment. For the adjustment time, see Chapter 1 JVM memory structure.
    • -Xmn: it is usually set to-Xmx/4 (this is the setting method for my internship in the enterprise, and the system runs normally, smoothly, and fast ), lin Hao recommended-Xmx/3, so-Xmn =-Xmx/4 ~ -Xmx/3
      • Adjustment time: too frequent minor GC
      • -Xmn is too small: minor GC is too frequent; small objects may also directly enter the old generation, leading to Full GC in advance.
      • -Xmn is too large: the young generation is too large, and the minor GC time is longer; the old generation is smaller, and the Full GC will frequently
      • Adjustment policy: If-Xmx is adjustable to a greater value, it is increased and-Xmn =-Xmx/4 ~ is maintained ~ -Xmx/3; if-Xmx cannot be increased, keep-Xmn =-Xmx/4 ~ -Xmx/3 is increased in the range of-Xmn. If-Xmn is not adjustable, increase-XX: Adjust vorratio to check the situation.
    • -XX: Invalid vorratio: The default value is 8.
      • -XX: Too large vorratio: Eden increases, Region vor decreases, and minor GC may decrease. However, because suvivor decreases, if the minor GC surviving object is greater than suvivor, it will directly enter the old generation.
      • -XX: Invalid vorratio is too small: Eden becomes smaller, Region vor becomes larger, and minor GC may increase. However, as suvivor becomes larger, more surviving objects can be stored, and objects entering the old generation may be reduced.
    • -XX: MaxTenuringThreshold: The default value is 15.
      • -XX: Too large vorratio: the object remains longer in the young generation, and may be reclaimed in the young generation without entering the old generation, however, during the replication, the VOR zone will occupy more space.
      • -XX: Too large vorratio: The survival time of the object in the young generation is shortened, and the object may enter the old generation early and lose the opportunity to be recycled in the young generation, however, there will be more memory in the SWAp vor area during the corresponding replication, which may prevent some large objects from directly entering the old generation.
    • -XX: MaxPermSize =-XX: PermSize
      • In actual development, jsp is not used in the foreground, and template engine technologies such as velocity are used.
      • Do not introduce irrelevant jar

3. Select a garbage collector

The two most common combinations in Enterprises: (most large enterprises use JDK1.6, so G1)

For detailed principles of the following two groups of garbage collectors, see Chapter 5 JVM garbage collector (1)

  • Parallel Scavenge/Parallel Old
    • Focus on throughput (the higher the throughput, the higher the CPU utilization)
    • It is mainly used to process many CPU computing tasks with fewer user interaction tasks.
    • It is also used to enable automatic JVM optimization while we stand by (-XX: + UseParallelOldGC,-XX: GCTimeRatio,-Xmx,-XX: + UseAdaptiveSizePolicy)
    • -XX: + UseParallelOldGC: Specifies to use this combination.
  • ParNew/CMS
    • Pay attention to the shortening of STW (the shorter the time, the better the user experience, and reduce the request timeout issue of some requests)
    • -XX: + UseConcMarkSweepGC: Specifies to use this combination.
    • -XX: CMSInitiatingOccupancyFraction: used to specify the percentage of space occupied by the old generation for garbage collection.
  • Description of the above two combinations
    • Generally, in an enterprise, there are a large number of CPUs and the CPU computing capability will not become a bottleneck. Therefore, for the CMS concurrent mark and concurrent clearing stage, CPU usage is not a big concern, but the focus on throughput of Parallel is not a big concern. After all, the CPU is powerful.
    • Therefore, ParNew/CMS is the first choice (when G1 is unavailable). Parallel Scavenge/Parallel Old is used only when the JVM wants to automatically manage the memory.

Note: during the actual optimization process, you can use the detection data of jstat, jconsole, visualVM, or GC logs for debugging. For specific examples, see "deep understanding of Java Virtual Machine (version 2) p142 optimizes the running speed of eclipse.

For the parameter meanings of GC logs and the format of GC logs for each garbage collector, see Java Virtual Machine (version 2) p89 and P224 in deep analysis of java web Technology (revised version)

 

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.