Go Eight tips for tuning JVM parameters

Source: Internet
Author: User

Here and you to share the JVM parameter tuning eight experience, JVM parameter tuning, this is a headache problem, bad settings, the JVM is constantly executing FULLGC, resulting in the entire system becomes very slow, the site can be stagnant for more than 10 seconds, I believe that through this study you have a new understanding of the JVM parameter tuning.

Examples of eight experiences on tuning JVM parameters

This article will introduce the JVM parameter tuning, which is a very headache problem, bad settings, the JVM constantly executing FULLGC, resulting in the entire system becomes very slow, the site can be stuck for more than 10 seconds, this situation if not every few minutes to come once, they can not stand. This stagnation can not be seen when testing, only the site PV reached hundreds of thousands of/day when the problem is exposed.

To configure the JVM parameters, you need to have a good understanding of the young generation, the old generation, the rescue space and the permanent generation, but also to understand the JVM memory management logic, and ultimately to adapt to their own applications. About JVM parameters you can search for a lot of things on the internet, and there are many examples that provide practice, and I have tested them in a variety of examples, and eventually there will be problems.

After several months of practice improvement, I gave the following experience on the JVM parameter tuning of the site (which requires no time to stall).

1:64-bit operating system is recommended, Linux 64-bit JDK is slower than 32-bit JDK, but eat more memory, more throughput.

The 2:XMX and XMS settings are as large as the MaxPermSize and minpermsize settings, which reduces the pressure on the size of the scaling heap.

3: Set some print JVM parameters when debugging, such as-XX:+PRINTCLASSHISTOGRAM-XX:+PRINTGCDETAILS-XX:+PRINTGCTIMESTAMPS-XX:+PRINTHEAPATGC-XLOGGC : Log/gc.log, so you can see some clues from the gc.log.

4: The system can be stopped when the problem may be GC or the problem of the program, more with Jmap and Jstack view, or Killall-3java, and then view the Java console log, can see a lot of problems. Once, the website suddenly very slow, jstack a look, originally is oneself writes the URLConnection connection too many did not release, changes the procedure to be OK.

5: Careful understanding of their own applications, if the use of the cache, then the older generation should be larger, the cache hashmap should not be unlimited long, it is recommended to use the LRU algorithm map cache, the maximum length of lrumap should be set according to the actual situation.

6: Garbage collection When the promotionfailed is a very headache, the general may be two reasons, the first reason is that the rescue space is not enough, the object in the rescue space should not be moved to the old generation, but the young generation and many objects need to put in the rescue space The second reason is that the old generation does not have enough space to accommodate the young generation, both of which turn to FULLGC and the site pauses for a long time. The first reason my final solution is to remove the rescue space, set the-xx:survivorratio=65536-xx:maxtenuringthreshold=0 can, The second reason my solution is to set Cmsinitiatingoccupancyfraction to a value (assuming 70), so that the old generation of space to 70% when the implementation of the CMS, old generation has enough space to accept from the young generation of objects.

7: In any case, the permanent generation will gradually become full, so go out to restart the Java server is necessary, I automatically restart every day.

8: The use of concurrent recycling, the younger generation of small, older generations to big, because the eldest brother with the use of concurrent recovery, even if the long point will not affect the other programs continue to run, the site will not pause.

My final configuration is as follows (System 8G memory), millions of PV per day no problem, the site did not stop, 2009 site did not because of memory problems down the machine.

  1. $java_args.= "-dresin.home= $SERVER _root
  2. -server-xms6000m-xmx6000m-xmn500m
  3. -xx:permsize=500M-xx:maxpermsize=500M
  4. -xx:survivorratio=65536
  5. -xx:maxtenuringthreshold=0
  6. -xnoclassgc
  7. -xx:+disableexplicitgc
  8. Xx:+useparnewgc-xx:+useconcmarksweepgc
  9. -xx:+usecmscompactatfullcollection
  10. -xx:cmsfullgcsbeforecompaction=0
  11. -xx:+cmsclassunloadingenabled
  12. -xx:-cmsparallelremarkenabled
  13. -xx:cmsinitiatingoccupancyfraction=
  14. -xx:softreflrupolicymspermb=0-xx:+printclasshistogram
  15. -xx:+printgcdetails-xx:+printgctimestamps-xx:+printheapatgc
  16. -xloggc:log/gc.log ";

Explain,-xx:survivorratio=65536,-xx:maxtenuringthreshold=0 is to remove the rescue space;

-XNOCLASSGC Disable garbage collection, performance will be a bit higher;

-XX:+DISABLEEXPLICITGC prohibit System.GC (), lest the programmer mistakenly call GC method to affect performance;

-XX:+USEPARNEWGC, the young generation of multi-threaded parallel recovery, so close;

With the CMS parameters are related to concurrent recycling, do not understand the Internet to search;

Cmsinitiatingoccupancyfraction, this parameter setting has great skill, basically satisfies (xmx-xmn) * (100-cmsinitiatingoccupancyfraction)/100>= Xmn will not appear promotionfailed. In my application xmx is the 6000,XMN is 500, then xmx-xmn is 5500 trillion, that is, the old generation has 5500 trillion, Cmsinitiatingoccupancyfraction=90 explained the old generation to 90% When the full time began to implement the old generation of garbage collection (CMS), then there is still 10% of the space is 5500*10%=550 trillion, so even if xmn (that is, the young generation of 500 trillion) all the objects are moved to the old generation, 550 trillion of space is enough, so as long as the above formula is satisfied, There will be no promotionfailed at the time of garbage collection;

SOFTREFLRUPOLICYMSPERMB This parameter I think it might be a bit of a use, the official explanation is softlyreachableobjectswillremainaliveforsomeamountoftimeafterthelasttimetheywerereferenced.

Thedefaultvalueisonesecondoflifetimeperfreemegabyteintheheap, I don't think it's necessary to wait 1 seconds;

Other on the net the JVM parameters are also more, it is estimated that most of them are not encountered promotionfailed, or access is too small no chance to encounter, (XMX-XMN) * (100-cmsinitiatingoccupancyfraction)/100 >=xmn This formula is absolutely original, really met Promotionfailed, still have to deal with it.

Go Eight tips for tuning JVM parameters

Related Article

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.