A JVM parameter configuration with better performance

G1 garbage collector (-XX:+UseG1GC) G1 (Garbage First): The garbage collector is a feature that can 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 compaction short-pause garbage collector. The G1 collector works differently from other collectors and does not distinguish between young and old generation spaces.
A better performance web server jvm parameter configuration:
-server//server mode
-Xmx2g //The maximum heap memory allowed by the JVM, allocated on demand
-Xms2g //The heap memory initially allocated by the JVM is generally configured the same as Xmx to prevent the JVM from re-allocating memory after each gc.
-Xmn256m //The memory size of the young generation, the entire JVM memory = young generation + old generation + persistent generation
-XX:PermSize=128m //Persistent generation memory size
-Xss256k //Set the stack size of each thread
-XX:+DisableExplicitGC //Ignore the manual call to GC, the call of System.gc() will become an air conditioner, without triggering GC at all
-XX:+UseConcMarkSweepGC //Concurrent Mark Sweep (CMS) collector
-XX:+CMSParallelRemarkEnabled //Reduce mark pause
-XX:+UseCMSCompactAtFullCollection //Compression of the old generation during FULL GC
-XX:LargePageSizeInBytes=128m //The size of the memory page
-XX:+UseFastAccessorMethods //Fast optimization of primitive types
-XX:+UseCMSInitiatingOccupancyOnly //Start CMS collection with manually defined initialization definition
-XX:CMSInitiatingOccupancyFraction=70 //Use cms as garbage collection to start CMS collection after using 70%
illustrate:
The ratio of -Xmn to -Xmx is about 1:9. If the new generation memory is set too large, the young gc time will be longer.
A good web system should be able to reclaim memory in young gc every time http request requests, full gc will never happen, of course, this is the 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 the same. The most important difference is that the xmn of the game server, that is, the young generation setting, is relatively large, and the relationship with Xmx is about 1:3, because the game server is generally a long connection. After the concurrency, a larger young generation heap memory is required. If the size is set, it will often cause young gc
Introduction to the JVM
一个性能较好的jvm参数配置以及jvm的简介
As can be seen from the above figure , the classification of JVM heap memory , JVM memory is divided into multiple independent parts.
Broadly speaking, JVM heap memory is divided into two parts - Young Generation and Old Generation.
young generation
The young generation is where all new objects are created. Garbage collection is triggered when the young generation memory space is used up. This garbage collection is called Minor GC. The young generation is divided into 3 parts - Enden area and two Survivor areas.
Key takeaways from the young generation space:
Most of the newly created objects are located in the Eden area.
Minor GC is performed when the Eden area is filled with objects. And transfer all surviving objects to one of the survivor areas.
Minor GC also checks for surviving objects and moves them to another survivor area. In this way, for a period of time, there will always be an empty survivor area.
After many GC cycles, objects that are still alive will be moved to the old generation memory space. Usually this is done by setting an age threshold before the young generation is eligible for promotion to the old generation.
old generation
The old generation memory contains long-lived objects and objects that survive multiple Minor GCs. Garbage collection is usually performed when the old generation memory is full. Old age garbage collection is called Major GC. Major GC will take more time.
Stop the World event
All garbage collections are "Stop the World" events because all application threads are stopped until the operation is complete (hence the name "Stop the World").
因为年轻代里的对象都是一些临时(short-lived )对象,执行Minor GC非常快,所以应用不会受到(“Stop the World”)影响。
由于Major GC会检查所有存活的对象,因此会花费更长的时间。应该尽量减少Major GC。因为Major GC会在垃圾回收期间让你的应用反应迟钝,所以如果你有一个需要快速响应的应用发生多次Major GC,你会看到超时错误。
垃圾回收时间取决于垃圾回收策略。这就是为什么有必要去监控垃圾收集和对垃圾收集进行调优。从而避免要求快速响应的应用出现超时错误。
永久代
永久代或者“Perm Gen”包含了JVM需要的应用元数据,这些元数据描述了在应用里使用的类和方法。注意,永久代不是Java堆内存的一部分。
永久代存放JVM运行时使用的类。永久代同样包含了Java SE库的类和方法。永久代的对象在full GC时进行垃圾收集。
方法区
方法区是永久代空间的一部分,并用来存储类型信息(运行时常量和静态变量)和方法代码和构造函数代码。
内存池
如果JVM实现支持,JVM内存管理会为创建内存池,用来为不变对象创建对象池。字符串池就是内存池类型的一个很好的例子。内存池可以属于堆或者永久代,这取决于JVM内存管理的实现。
运行时常量池
运行时常量池是每个类常量池的运行时代表。它包含了类的运行时常量和静态方法。运行时常量池是方法区的一部分。
Java栈内存
Java栈内存用于运行线程。它们包含了方法里的临时数据、堆里其它对象引用的特定数据。
Java垃圾回收会找出没用的对象,把它从内存中移除并释放出内存给以后创建的对象使用。Java程序语言中的一个最大优点是自动垃圾回收,不像其他的程序语言那样需要手动分配和释放内存,比如C语言。
垃圾收集器是一个后台运行程序。它管理着内存中的所有对象并找出没被引用的对象。所有的这些未引用的对象都会被删除,回收它们的空间并分配给其他对象。
一个基本的垃圾回收过程涉及三个步骤
标记:这是第一步。在这一步,垃圾收集器会找出哪些对象正在使用和哪些对象不在使用。
正常清除:垃圾收集器清会除不在使用的对象,回收它们的空间分配给其他对象。
压缩清除:为了提升性能,压缩清除会在删除没用的对象后,把所有存活的对象移到一起。这样可以提高分配新对象的效率。
简单标记和清除方法存在两个问题:
效率很低。因为大多数新建对象都会成为“没用对象”。
经过多次垃圾回收周期的对象很有可能在以后的周期也会存活下来。
上面简单清除方法的问题在于Java垃圾收集的分代回收的,而且在堆内存里有年轻代和年老代两个区域。
Java垃圾回收类型
这里有五种可以在应用里使用的垃圾回收类型。
仅需要使用JVM开关就可以在我们的应用里启用垃圾回收策略。
Serial GC(-XX:+UseSerialGC):Serial GC使用简单的标记、清除、压缩方法对年轻代和年老代进行垃圾回收,即Minor GC和Major GC。Serial GC在client模式(客户端模式)很有用,比如在简单的独立应用和CPU配置较低的机器。这个模式对占有内存较少的应用很管用。
Parallel GC(-XX:+UseParallelGC):除了会产生N个线程来进行年轻代的垃圾收集外,Parallel GC和Serial GC几乎一样。这里的N是系统CPU的核数。我们可以使用 -XX:ParallelGCThreads=n 这个JVM选项来控制线程数量。并行垃圾收集器也叫throughput收集器。因为它使用了多CPU加快垃圾回收性能。Parallel GC在进行年老代垃圾收集时使用单线程。
Parallel Old GC(-XX:+UseParallelOldGC):和Parallel GC一样。不同之处,Parallel Old GC在年轻代垃圾收集和年老代垃圾回收时都使用多线程收集。
并发标记清除(CMS)收集器(-XX:+UseConcMarkSweepGC):CMS收集器也被称为短暂停顿并发收集器。它是对年老代进行垃 圾收集 的。CMS收集器通过多线程并发进行垃圾回收,尽量减少垃圾收集造成的停顿。CMS收集器对年轻代进行垃圾回收使用的算法和Parallel收集器一样。 这个垃圾收集器适用于不能忍受长时间停顿要求快速响应的应用。可使用 -XX:ParallelCMSThreads=n JVM选项来限制CMS收集器的线程数量。
G1垃圾收集器(-XX:+UseG1GC) G1(Garbage First):垃圾收集器是在Java 7后才可以使用的特性,它的长远目标时代替CMS收集器。G1收集器是一个并行的、并发的和增量式压缩短暂停顿的垃圾收集器。G1收集器和其他的收集器运 行方式不一样,不区分年轻代和年老代空间。它把堆空间划分为多个大小相等的区域。当进行垃圾收集时,它会优先收集存活对象较少的区域,因此叫 “Garbage First”。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326972186&siteId=291194637