第5章 Available GC

The Java HotSpot VM includes three different types of collectors, each with different performance characteristics.

Java虚拟机有三种不同类型的gc,他们有不同的特性。

顺序gc

The serial collector uses a single thread to perform all garbage collection work, which makes it relatively efficient because there is no communication overhead between threads. It is best-suited to single processor machines, because it cannot take advantage of multiprocessor hardware, although it can be useful on multiprocessors for applications with small data sets (up to approximately 100 MB). The serial collector is selected by default on certain hardware and operating system configurations, or can be explicitly enabled with the option -XX:+UseSerialGC.

顺序gc使用一个单独的线程来进行所有的垃圾回收工作。由于不需要进行线程间通信,所以相对高效。顺序gc适用于单处理器及有多核处理器的小规模程序。使用命令行参数-XX:+UseSerialGC来明确指定使用顺序gc。

并行gc

The parallel collector (also known as the throughput collector) performs minor collections in parallel, which can significantly reduce garbage collection overhead. It is intended for applications with medium-sized to large-sized data sets that are run on multiprocessor or multithreaded hardware. The parallel collector is selected by default on certain hardware and operating system configurations, or can be explicitly enabled with the option -XX:+UseParallelGC.

并行gc对于minor gc使用并行方式执行,可以大大提高效率。并行gc特别适合于,运行在多核多线程机器上的,中到大型规模的应用程序。使用命令行参数-XX:+UseParallelGC来明确指定使用并行gc。

Parallel compaction is a feature that enables the parallel collector to perform major collections in parallel. Without parallel compaction, major collections are performed using a single thread, which can significantly limit scalability. Parallel compaction is enabled by default if the option -XX:+UseParallelGC has been specified. The option to turn it off is -XX:-UseParallelOldGC

并行gc在进行major gc的时候使用并行压缩技术。如果不使用并行压缩,那么并行gc在进行major gc的时候只能使用单一线程进行回收,这会极大的影响major gc的效能。当指定命令行参数-XX:+UseParallelGC时并行压缩模式默认是打开的,可是使用参数-XX:-UseParallelOldGC来指定并行gc时关闭并行压缩模式。

并发gc

The mostly concurrent collector performs most of its work concurrently (for example, while the application is still running) to keep garbage collection pauses short. It is designed for applications with medium-sized to large-sized data sets in which response time is more important than overall throughput because the techniques used to minimize pauses can reduce application performance. The Java HotSpot VM offers a choice between two mostly concurrent collectors; see The Mostly Concurrent Collectors. Use the option -XX:+UseConcMarkSweepGC to enable the CMS collector or -XX:+UseG1GC to enable the G1 collector.

并发gc是指在程序运行的时间里同时并发进行垃圾回收,这样做的好处在于可以尽可能的缩短程序暂停时间。并发gc适合于多响应时间要求比较高的应用程序。Java虚拟机提供了两种并发gc,使用参数-XX:+UseConcMarkSweepGC来明确指定使用CMS收集器,使用参数-XX:+UseG1GC来明确指定使用G1收集器。

汇总

选择gc

Unless your application has rather strict pause time requirements, first run your application and allow the VM to select a collector. If necessary, adjust the heap size to improve performance. If the performance still does not meet your goals, then use the following guidelines as a starting point for selecting a collector.

除非你的程序有相当严格的暂停时间要求,否则你应当让虚拟机自己决定使用gc的类型。提升性能的首选应该是调整堆的大小。如果调整堆的大小不能带来显著的性能提升,那么根据如下原则来进行gc的选择:

If the application has a small data set (up to approximately 100 MB), then

select the serial collector with the option -XX:+UseSerialGC.

如果程序使用的数据集合在100MB左右,那么选择-XX:+UseSerialGC顺序gc即可。

If the application will be run on a single processor and there are no pause time requirements, then let the VM select the collector, or select the serial collector with the option -XX:+UseSerialGC.

如果应用程序运行在单核处理器系统上,并且没有暂停时间的需求,应当让虚拟机自动选择gc,或者使用顺序收集器

If (a) peak application performance is the first priority and (b) there are no pause time requirements or pauses of 1 second or longer are acceptable, then let the VM select the collector, or select the parallel collector with -XX:+UseParallelGC.

如果程序性能是首要需求,并且程序的暂停时间稍长可以被接受,那么应当让虚拟机选择gc类型,或者使用并行gc。

If response time is more important than overall throughput and garbage collection pauses must be kept shorter than approximately 1 second, then select the concurrent collector with -XX:+UseConcMarkSweepGC or -XX:+UseG1GC.

如果程序的响应时间是关键因素,并且要求尽可能短的暂停,那么应当选择并发gc,使用-XX:+UseConcMarkSweepGC或者-XX:+UseG1GC指令。

Java 8 VM GC Tunning Guide Charter 5的更多相关文章

  1. Java 8 VM GC Tunning Guide Charter 6

    第六章 并行GC The Parallel Collector The parallel collector (also referred to here as the throughput coll ...

  2. Java 8 VM GC Tunning Guide Charter 7-8-b

    第七章 并发gc Java 8提供两种并发gc,CMS和G1 Concurrent Mark Sweep (CMS) Collector This collector is for applicati ...

  3. Java 8 VM GC Tunning Guild Charter 9-b

    第九章 G1 GC The Garbage-First (G1) garbage collector is a server-style garbage collector, targeted for ...

  4. Java 8 VM GC Tuning Guide Charter3-4

    第三章 Generations One strength of the Java SE platform is that it shields the developer from the compl ...

  5. Java 8 VM GC Tuning Guide Charter2

    第二章 Ergonomics Ergonomics is the process by which the Java Virtual Machine (JVM) and garbage collect ...

  6. JVM:从实际案例聊聊Java应用的GC优化

    原文转载自美团从实际案例聊聊Java应用的GC优化,感谢原作者的贡献 当Java程序性能达不到既定目标,且其他优化手段都已经穷尽时,通常需要调整垃圾回收器来进一步提高性能,称为GC优化.但GC算法复杂 ...

  7. 并发测试 java.lang.OutOfMemoryError: GC overhead limit exceeded Xms Xmx 阻塞请求 单节点 请求分发 负载均衡

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:705) at javax.servlet.http.HttpServlet.se ...

  8. java虚拟机(十三)--GC调优思路

    GC调优对我们开发人员来说,如果你想要技术方面一直发展下去,这部分内容的了解是必不可少的,jvm对于工作.面试来说都很重要,GC调优的问题 更是重中之重,因为是对你jvm学习内容的实践,知识只有应用实 ...

  9. JAVA中的GC机制详解

    优秀Java程序员必须了解的GC工作原理 一个优秀的Java程序员必须了解GC的工作原理.如何优化GC的性能.如何与GC进行有限的交互,因为有一些应用程序对性能要求较高,例如嵌入式系统.实时系统等,只 ...

随机推荐

  1. 十七、Android学习笔记_Android 使用 搜索框

    1.在资源文件夹下创建xml文件夹,并创建一个searchable.xml: android:searchSuggestAuthorityshux属性的值跟实现SearchRecentSuggesti ...

  2. Git之使用

    一大清早的,正在熟睡的我竟然被冻醒了,这天好冷啊,没事就先来扯一下犊子吧:我发现我养成了一个“怪”习惯:我老是一大早起来打开电脑就撸代码,到了中午和下午就去干别的事不想敲了.我们寝室的宿友总是被我敲代 ...

  3. 根据数据库内容动态生成html页面

    之前使用了很多方法,但是都很复杂. 项目里包括了数据库的管理页面,对数据库进行修改(新增,插入,删除)等之后,在另一个页面使用. 使用时采用按下相应label弹出所有信息的方法,以html的形式将数据 ...

  4. Linux下用freetds连接mssql中文乱码的问题【参考2】

    php5.3的情况下,用pdo的dblib驱动无法连接mssql的,根据官方的描述,5.2已经修改这个bug,5.3没有. 用php自带的mssql函数可以的.编译freetds,php_mssql, ...

  5. List.Select按字符串选择属性

    不知道大家有没有遇到这样的情况:List使用Lambda表达式的时候,想要选择项的某个属性列. 例如,选择编号ID: var idList=list.Select(o=>o.ID).ToList ...

  6. 让apache与mysql随着系统自动启动

    让apache与mysql随着系统自动启动 在Linux中有一个文件/etc/rc.d/rc.local文件,其系统在启动时会自动加载该文件,我们可以把要启动的服务放入这个文件中即可. 添加以下代码:

  7. C#工具介绍

    VisualStudio是微软的官方提供的.NET开发工具. 除了VisualStudio外,还有一些开源的.NET开发IDE. MonoDevelop.SharpDevelop等. 开发未必需要使用 ...

  8. 《gpg文件加密的使用》RHEL6

    甲端: 首先是要生成一对密钥: 提示是否要生成2048个字节的密钥对:   下面都是生成密钥对时的步骤: 按“o”键开始生成密钥对: 提示要我给密钥对加个密码: 输入2次 之后密钥对的字符需要我按键盘 ...

  9. 《linux源代码包的编译安装》RHEL6

    linux下源代码包的编译安装其实没那么复杂. 我是win7系统装的虚拟机,就简单说下: 举个简单的例子: http://www.openssl.org/ 这是openssl的官网,下载openssl ...

  10. 《DNS加密更新》RHEL6

    DNS加密更新: 继DNS更新之后,现在又玩DNS加密更新,差不多. DNS更新指定一台主机,那台主机或多台主机来更新它,其他主机没权限. DNS加密更新,谁有密码说就可以更新. 做过上次的更新之后, ...