As we’ve seen, the performance of the garbage collector is not determined by the number of dead objects, but rather by the number of live ones. The more objects die, the faster garbage collection is. If every object in the heap were to be garbage-collected, the GC cycle would be nearly instantaneous. Additionally, the garbage collector must suspend the execution of the application to ensure the integrity of the object trees. The more live objects are found, the longer the suspension, which has a direct impact on response time and throughput.

This fundamental tenet of garbage collection and the resulting effect on application execution is called the garbage-collection pause or GC pause time. In applications with multiple threads, this can quickly lead to scalability problems.

Figure 2.4: This graphic from an Oracle GC Tuning article illustrates the performance hit of GC suspensions with increasing number of CPUs. (Source: http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html)

Figure 2.4 illustrates the impact that GC suspensions have on the throughput of multithreaded applications. An application that spends 1% of its execution time on garbage collection will loose more than 20% throughput on a 32-processor system. If we increase the GC time to 2%, the overall throughput will drop by another 20%. Such is the impact of suspending 32 executing threads simultaneously!

There are two commonly used methods to reduce GC pause time:

  1. Reducing suspension time by adjusting the mark-and-sweep algorithm.
  2. Limiting the number of objects that need to be marked.

But before we examine ways to improve garbage-collection performance, you should understand memory fragmentation, which impacts suspension time and application performance.

About Fragmented Memory and Finding a Big Enough Hole

Whenever we create a new object in Java, the JVM automatically allocates a block of memory large enough to fit the new object on the heap. Repeated allocation and reclamation leads to memory fragmentation, which is similar to disk fragmentation. Memory fragmentation leads to two problems:

  1. Reduced allocation speed: The JVM tracks free memory in lists organized by block size. To create a new object, Java searches through the lists to select and allocate an optimally sized block. Fragmentation slows the allocation process, effectively slowing the application execution.
  2. Allocation Errors: Allocation errors happen when fragmentation becomes so great that the JVM is unable to allocate a sufficiently large block of memory for a new object.

Java does not rely on the operating system to solve these problems and must deal with these itself. Java avoids memory fragmentation by executing compaction (Figure 2.5) at the end of a successful GC cycle. The process is very similar to hard-disk defragmentation.

Figure 2.5: When the heap becomes fragmented due to repeated allocations and garbage collections, the JVM executes a compaction step, which aligns all objects neatly and closes all holes.

Compacting simply moves all live objects to one end of the heap, which effectively closes all holes. Objects can be allocated at full speed (no free lists are needed anymore), and problems creating large objects are avoided.

The downside is an even longer GC cycle, and since most JVMs suspend the application execution during compaction, the performance impact can be considerable.

The Impact of Garbage Collection on Application Performance的更多相关文章

  1. How Garbage Collection Really Works

    Java Memory Management, with its built-in garbage collection, is one of the language's finest achiev ...

  2. Java Garbage Collection Basics--转载

    原文地址:http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html Overview Purpose ...

  3. Garbage Collection Optimization for High-Throughput and Low-Latency Java Applications--转载

    原文地址:https://engineering.linkedin.com/garbage-collection/garbage-collection-optimization-high-throug ...

  4. AutoReleasePool 和 ARC 以及Garbage Collection

    AutoReleasePool autoreleasepool并不是总是被auto 创建,然后自动维护应用创建的对象. 自动创建的情况如下: 1. 使用NSThread的detachNewThread ...

  5. .NET:CLR via C#The Managed Heap and Garbage Collection

    Allocating Resources from the Managed Heap The CLR requires that all objects be allocated from the m ...

  6. 2.5 – Garbage Collection 自动垃圾回收 Stop-the-world vs. incremental vs. concurrent 垃圾回收策略

    2.5 – Garbage Collection  自动垃圾回收 Lua 5.3 Reference Manual http://www.lua.org/manual/5.3/manual.html# ...

  7. Valid page threshold based garbage collection for solid state drive

    A method for garbage collection in a solid state drive (SSD) includes determining whether the SSD is ...

  8. Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译

    本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...

  9. [翻译]Java垃圾收集精粹(Java Garbage Collection Distilled)

    source URL: http://www.infoq.com/articles/Java_Garbage_Collection_Distilled Name: Java Garbage Colle ...

随机推荐

  1. 怎么在spring官网上下载spring的jar包, 源代码和文档?

    现在 http://repo.spring.io/release/org/springframework/spring/第一种,简单粗暴直接 1 http://repo.springsource.or ...

  2. unity 3d-Easy Touch 3教程 转

    Easy Touch 教程 转自:http://www.unitymanual.com/thread-31332-1-1.html 1.import “Easy Touch 3”的资源包 2.创建人物 ...

  3. 谈谈java中的WeakReference

    Java语言中为对象的引用分为了四个级别,分别为 强引用 .软引用.弱引用.虚引用. 本文只针对java中的弱引用进行一些分析,如有出入还请多指正. 在分析弱引用之前,先阐述一个概念:什么是对象可到达 ...

  4. mac上xampp配置

    sudo su /Applications/XAMPP/xamppfiles/xampp security

  5. 快捷设置IE代理小工具

    时间:2015-02-06 起因: 公司新装了PLM系统,用这个系统必须使用指定IP段的IP才能访问.所以为了还能愉快的继续使用代理进行特定网站的访问,我们必须要频繁的去设置IE代理,这也太麻烦了吧. ...

  6. 高性能图文混排框架,构架顺滑的iOS应用-b

    About GallopGallop是一个功能强大.性能优秀的图文混排框架. Features主要用于解决以下需求: 滚动列表的性能优化.Gallop使用异步绘制.视图层级合并.观察mainRunlo ...

  7. hdu 2566 统计硬币

    http://acm.hdu.edu.cn/showproblem.php?pid=2566 假设一堆由1分.2分.5分组成的n个硬币总面值为m分,求一共有多少种可能的组合方式(某种面值的硬币可以数量 ...

  8. java程序练习:猜字母

    猜字母程序=数据结构+算法 首先:定义数据结构1.找名词Input:输入变量Output:输出变量隐含:找到隐含的变量,如字符串 其次:定义算法,程序的处理 最后:按照顺序,逐步实现 注意:1.基本数 ...

  9. springMVC+MyBatis+Spring 整合(2)

    mybatis 与Spring 的整合. 1.导入Spring 和Springmvc的包 pom <project xmlns="http://maven.apache.org/POM ...

  10. sublime 配置g++

    资料来源: http://blog.csdn.net/leonsc/article/details/5853614 http://www.cnblogs.com/zhenglichina/archiv ...