In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to configure JVM parameters. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
A JVM parameter configuration with better performance
G1 garbage collector (- XX:+UseG1GC) G1 (Garbage First): the garbage collector is a feature that can only be used after Java 7, and its long-term goal is to replace the CMS collector. The G1 collector is a parallel, concurrent, and incremental compression short pause garbage collector. The G1 collector runs differently from other collectors in that it does not distinguish between the younger generation and the older generation.
A better performance web server jvm parameter configuration:
-server// server mode
-Xmx2g / / JVM maximum allowed allocation of heap memory, allocated on demand
-the heap memory initially allocated by Xms2g / / JVM is generally configured the same as Xmx to avoid JVM reallocation after each gc.
-Xmn256m / / memory size of younger generation, whole JVM memory = younger generation + older generation + persistent generation
-XX:PermSize=128m / / persistent memory size
-Xss256k / / sets the stack size for each thread
-XX:+DisableExplicitGC / / ignores the manual call to GC, and the call to System.gc () becomes an air conditioner without triggering GC at all.
-XX:+UseConcMarkSweepGC / / concurrent tag cleanup (CMS) collector
-XX:+CMSParallelRemarkEnabled / / reduce mark pause
-XX:+UseCMSCompactAtFullCollection / / Compression of the older generation in FULL GC
-XX:LargePageSizeInBytes=128m / / memory page size
-XX:+UseFastAccessorMethods / / Fast optimization of primitive types
-XX:+UseCMSInitiatingOccupancyOnly / / start CMS collection with manual initialization definition
-XX:CMSInitiatingOccupancyFraction=70 / / start CMS collection after using 70% of cms as garbage collection
Description:
The ratio of-Xmn to-Xmx is about 1:9. If the Cenozoic memory is set too high, the young gc time will be longer.
A good Web system should be that every http request request memory can be reclaimed in young gc, full gc will never happen, of course, this is the most ideal situation.
The value of xmn should be set as small as possible on the premise that it is sufficient (enough for http concurrent requests).
The configuration ideas of the web server and the game server are not quite the same. The most important difference is that the xmn of the game server, that is, the young generation, is relatively large, which is about 1:3 with Xmx, because the game server is generally a long connection, which requires a large amount of young generation heap memory after maintaining a certain amount of concurrency. If the size is set, it will often cause young gc.
A brief introduction to JVM
You can see the classification of JVM heap memory from the figure above. JVM memory is divided into several separate parts.
Broadly speaking, JVM heap memory is divided into two parts-the younger generation (Young Generation) and the older generation (Old Generation).
Young generation
The younger generation is the place where all new objects are born. Garbage collection will be triggered when the lightweight memory space is used up that year. This garbage collection is called Minor GC. The younger generation is divided into three parts-Enden region and two Survivor regions.
The main points of the younger generation space:
Most newly created objects are located in the Eden zone.
Minor GC is executed when the Eden area is filled with objects. And transfer all the surviving objects to one of the survivor areas.
Minor GC also examines the surviving objects and moves them to another survivor area. In this way, there is always an empty survivor area for a period of time.
After several GC cycles, objects that are still alive are transferred to the older generation memory space. This is usually done by setting an age threshold before the younger generation is eligible for promotion to the older generation.
The old generation
The memory of the older generation contains objects that have survived for a long time and objects that have survived multiple Minor GC. Garbage collection is usually carried out in the old days when memory is full. Garbage collection in the old days was called Major GC. Major GC will take more time.
Stop the World event
All garbage collection is a "Stop the World" event because all application threads stop until the operation is complete (so it's called "Stop the World").
Because the objects in the younger generation are short-lived objects, the execution of Minor GC is very fast, so the application will not be affected by ("Stop the World").
Because Major GC examines all living objects, it takes longer. Major GC should be reduced as much as possible. Because Major GC can slow your application during garbage collection, if you have an application that requires a quick response to Major GC multiple times, you will see a timeout error.
Garbage collection time depends on the garbage collection strategy. This is why it is necessary to monitor and tune garbage collection. So as to avoid timeout errors in applications that require fast response.
Permanent generation
The permanent generation, or "Perm Gen", contains the application metadata required by JVM, which describes the classes and methods used in the application. Note that permanent generation is not part of the Java heap memory.
Permanently holds the classes used by the JVM runtime. The permanent generation also contains the classes and methods of the Java SE library. Objects of permanent generation are garbage collected during full GC.
Method area
The method area is part of the permanent generation space and is used to store type information (runtime constants and static variables) and method code and constructor code.
Memory pool
If the JVM implementation supports it, JVM memory management creates a memory pool for immutable objects. String pooling is a good example of a memory pool type. Memory pools can belong to a heap or permanent generation, depending on the implementation of JVM memory management.
Running constant pool
The runtime constant pool is the runtime representative of each class constant pool. It contains the runtime constants and static methods of the class. The run-time pool is part of the method area.
Java stack memory
Java stack memory is used to run threads. They contain temporary data in the method and specific data referenced by other objects in the heap.
Java garbage collection
Java garbage collection finds useless objects, removes it from memory and releases memory for later created objects to use. One of the biggest advantages of Java programming languages is automatic garbage collection, which does not require manual allocation and release of memory like other programming languages, such as C.
The garbage collector is a background running program. It manages all objects in memory and finds objects that are not referenced. All these unreferenced objects are deleted, their space is reclaimed and allocated to other objects.
A basic garbage collection process involves three steps:
Mark: this is the first step. In this step, the garbage collector finds out which objects are in use and which are not.
Normal cleanup: the garbage collector cleans up objects that are not in use and reclaims their space for other objects.
Compression cleanup: to improve performance, compression cleanup moves all living objects together after deleting useless objects. This improves the efficiency of allocating new objects.
There are two problems with simple marking and clearing methods:
It's inefficient. Because most new objects will become "useless objects".
Objects that have gone through multiple garbage collection cycles are likely to survive later cycles.
The problem with the simple cleanup method above is that Java garbage collection is recycled from generation to generation, and there are two areas of heap memory: the younger generation and the older generation.
Java garbage collection type
Here are five types of garbage collection that can be used in applications.
Just use the JVM switch to enable the garbage collection policy in our application.
SerialGC (- XX:+UseSerialGC): SerialGC uses simple marking, clearing, and compression methods to garbage collect the younger and older generations, namely Minor GC and Major GC. Serial GC is useful in client mode (client mode), such as in simple stand-alone applications and machines with low CPU configurations. This mode works well for applications with less memory.
ParallelGC (- XX:+UseParallelGC): ParallelGC and Serial GC are almost the same except that N threads are generated for the younger generation of garbage collection. The N here is the kernel number of the system CPU. We can use the JVM option-XX:ParallelGCThreads=n to control the number of threads. The parallel garbage collector is also called the throughput collector. Because it uses multiple CPU to speed up garbage collection performance. Parallel GC uses a single thread for older generation garbage collection.
ParallelOldGC (- XX:+UseParallelOldGC): same as Parallel GC. The difference is that Parallel Old GC uses multithreaded collection for both the younger generation and the older generation of garbage collection.
Concurrent tag cleanup (CMS) collector (- XX:+UseConcMarkSweepGC): the CMS collector is also known as a temporary pause concurrent collector. It is a collection of the elderly. The CMS collector performs garbage collection through multi-thread concurrency to minimize the pause caused by garbage collection. The CMS collector uses the same algorithm for garbage collection for the younger generation as the Parallel collector. This garbage collector is suitable for applications that cannot tolerate long pauses for quick response. You can use the-XX:ParallelCMSThreads=n JVM option to limit the number of threads in the CMS collector.
G1 garbage collector (- XX:+UseG1GC) G1 (Garbage First): the garbage collector is a feature that can only be used after Java 7, and its long-term goal is to replace the CMS collector. The G1 collector is a parallel, concurrent, and incremental compression short pause garbage collector. The G1 collector runs differently from other collectors in that it does not distinguish between the younger generation and the older generation. It divides the heap space into multiple areas of equal size. When doing garbage collection, it gives priority to collecting areas with fewer surviving objects, so it is called "Garbage First".
This is the end of the article on "how to configure JVM parameters". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.