The Impact of Garbage Collection on Application Performance
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 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:
- Reducing suspension time by adjusting the mark-and-sweep algorithm.
- 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:
- 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.
- 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.
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的更多相关文章
- How Garbage Collection Really Works
Java Memory Management, with its built-in garbage collection, is one of the language's finest achiev ...
- Java Garbage Collection Basics--转载
原文地址:http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html Overview Purpose ...
- Garbage Collection Optimization for High-Throughput and Low-Latency Java Applications--转载
原文地址:https://engineering.linkedin.com/garbage-collection/garbage-collection-optimization-high-throug ...
- AutoReleasePool 和 ARC 以及Garbage Collection
AutoReleasePool autoreleasepool并不是总是被auto 创建,然后自动维护应用创建的对象. 自动创建的情况如下: 1. 使用NSThread的detachNewThread ...
- .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 ...
- 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# ...
- 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 ...
- Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译
本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...
- [翻译]Java垃圾收集精粹(Java Garbage Collection Distilled)
source URL: http://www.infoq.com/articles/Java_Garbage_Collection_Distilled Name: Java Garbage Colle ...
随机推荐
- IE下的bug解决方案
1.IE6下的双边距bug <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
- Perl中的正则表达
前几天用到了Perl语言,主要看了一下Perl中的正则表达式,在各种网页语言中,正则表达式在处理字符串的时候十分有用,所以这里就简单说一下在Perl中正则表达式的应用. 先上代码 #!/usr/bin ...
- 《C和指针》 读书笔记 -- 第13章 高级指针话题
1.函数指针 int (*f)(); int *(*f[])(); 用途: [1]回调函数 e.g. /*在一个单链表中查找指定值*/ Node *search_list(Node *node,voi ...
- ajax的post用法
<button>点击之后,显示ajax返回的数据</button> 首先在页面上新建了一个按钮,点击这个按钮后,执行ajax操作,并将返回的字符串显示在按钮上. 下面是ajax ...
- linux set,env和export
set,env和export这三个命令都可以用来显示shell变量 set 显示当前shell的变量,包括当前用户的变量 env 显示当前用户的变量 export 显示当前导出成用户变量的shell变 ...
- 在Qt Creator中添加OpenCV库
在项目的pro文件中添加如下代码:INCLUDEPATH += D:/opencv/build/include win32:CONFIG(debug, debug|release): {LIBS += ...
- iOS CoCoa编程中视图控制器与视图类(转)
分类: iPhone2012-05-28 11:19 837人阅读 评论(0) 收藏 举报 cocoa编程iosuinavigationcontrolleruiviewiphone iPhone编程规 ...
- iOS 的UINavigationController详解与使用添加UIBarButtonItem
转发自:http://blog.csdn.net/totogo2010/article/details/7681879 分类: iOS开发入门2012-06-21 11:10 53077人阅读 评论( ...
- Lua基础之coroutine(协程)
概括:1.创建协程2.coroutine的函数3.coroutine的基本流程4.yield对coroutine流程的干预5.resume, function()以及yield之间的参数传递和返回值传 ...
- ajax,json和$.each()
json返回的时候,只需要展示部分字段,如果是 ajax从后台获取结果处理,可以使用.select() 等处理结合匿名类,生成需要的字段的匿名类json字符串,返回前端,可以使用$.parseJson ...