Home > Java > javaTutorial > body text

Summary and analysis of JVM tuning techniques

高洛峰
Release: 2017-01-23 10:15:23
Original
1136 people have browsed it

This is a technical article. If you are looking for articles about GC or adjusting internal purity, please read my other articles. Since this is a summary of JVM tuning, I won’t talk nonsense. The following methods have been collected from various aspects:
1. Upgrade the JVM version. If 64-bit is available, use a 64-bit JVM.​
Basically there is nothing to explain, it is very simple to upgrade the JVM to the latest version. If you are still using JDK1.4 or even an earlier JVM, the first thing you have to do is upgrade. Because the JVM from 1.4->1.5->1.6 is not just a version number upgrade, or just adding a bunch of new language features to it, it is as simple as that. Instead, major improvements have been made to the JVM. Every version upgrade brings huge performance upgrades. Especially when SUN realizes that Java is everything to a confidant (a bit exaggerated, but even the stock number has been changed to JAVA, haha). If you often visit SUN's JVM forum, you will find that there are actually so many problems with the JVM. If you cannot upgrade to 1.6 for various reasons, you can upgrade to the latest version of that version.
2. Choose a correct GC (Gargage Collection).
Because when the JAVA program GCs, the current program will be stopped. Especially during Full GC, it will stay for a long time. Generally for GUI programs, it is difficult to accept (think about when Eclipse is paused). After JAVA5, several types of GC come with it. You can choose the one that suits you. There are four types of Serial Collector, Parallel collector, Concurrent Collector, and Train Collector (obsolete). Parallel collection is used in the latter several times, so it is theoretically more efficient (you are required to have more than 2CUP, but now multi-core is becoming more popular, haha). Tip: After changing the GC type, increase the amount of JVM memory appropriately.
3. Set the memory size correctly. Set the size correctly for each area (young, old, perm) in the JVM heap.
This is the most difficult adjustment, because this adjustment will directly affect the efficiency of GC. And since the types of each program are different, there is no universal data. In addition to a few common rules, you need to use tools (jstat, jvmstat, jconsole, etc.) to adjust carefully. Several commonly used guidelines are mentioned below. Usually use a few parameters to adjust -Xms -Xmx-XX:MaxPermSize.
3.1 Increasing the value of -XX:NewRatio (NewSize/MaxNewSize) will reduce the number of young gcs, but increase the time of old gcs.
3.2 Method to increase normal GC (reduce Full GC). Increase the size of the young area (up to 40%) and oversize the Survivor area. Keep more objects in young gen.
4. Reduce the usage of classes, pay attention to the load and unload of classes, and reduce the number of JSP pages.
Classes are actually objects and will be directly allocated in the perm area. Even Full GC will rarely collect them. JSP will also be allocated to the perm area, with the same effect. If perm is too large and exceeds the XX:MaxPermSize value, an OutOfMemoryError: PermGen space exception will occur. The solution is to increase the -XX:MaxPermSize value.
5. Avoid using -Xnoclassgc
6. If it is an RMI program, pay attention to adjusting the RMI DGC time.
The following are a few things you should pay attention to when writing programs. GC can also be reduced to improve JVM performance.
1. Do not use the System.gc() method.
Because it will generate Full GC.
2. Allocate as few large temporary objects (with short life cycles) as possible
They may be allocated directly to the old area. The old area will only be collected during Full GC.
3. Avoid using the finalize() method.
finalize() will increase the burden on GC, use java.lang.ref instead.

For more articles related to summary and analysis of JVM tuning techniques, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!