Java Performance Tuning笔记

pdf在这里: http://mfinocchiaro.files.wordpress.com/2008/07/java-virtual-machine-neutral.pdf

其实这篇文章比较早,主要是针对当时的java 4,java 5,只是一个基本参考.

HotSpot VM Heap Layout
Young Generation: Eden Spce | Suvivor Space(From Space & To Space)
Old Generation: Tenured Space
Permanent Generation: Permanent Space
Young Generatio大小使用-Xmn选项指定,而Suvivor Space大小则用-XX:SurviorRatio指定,注意From Space和To Space大小相同,该选项指定的是Eden Space大小/From(or to) Space大小.
如果Young generation满了就调用Scavenge GC(即Minor GC),Eden Space中未被回收的对象进入From,而每次minor GC结束之后,from和to指针对换.如果一个对象在几次minor gc之后仍然幸存则从to space提升到old generation.
old generation大小使用-Xms(初始大小)和-Xmx(最大大小)指定,32位系统在不同架构下Xmx有大小限制.指定-d64后使用64位jvm,性能下降5%-20%.
Permanent Generation用于保留class file.主要是编译的class和jsp页面.如果该空间满了会调用Full GC,使用-XX:PermSize和-XX:MaxPermSize指定.
RMI协议或者java用户可以显式调用System.gc()调用Full GC,可以使用-XX:+DisableExplicitGC选项禁止显式调用.
Default Garbage Collection Algorithms
分别是Minor GC和Full GC.
Java1.4后Minor GC可以使用多线程(ParallelGCThreads),但如果多于CPU核心数仍会是瓶颈.
Full GC在回收时会对heap中对象扫描两次,如果第二次扫描时仍未完成回收,它们将被加入下次Full GC的回收队列.因此FullGC非常耗时,jvm tuning就是要减少Full GC并确保不发生OOME(Out Of Memory Error).

Alternative Garbage Collectors

Parallel Copy GC:用在Eden Space,使用选项-XX:+UseParNewGC和-XX:ParallelGCThreads指定.

Concurrent Mark-and-Sweep:基于mark-and-sweep算法进行回收,使用选项-xx:UseConMarkSweepGC指定.

-XX:+UseCMSCompactAtFullCollection  default true 对老年代进行压缩,可能影响性能,但是可以消除碎片。
-XX:CMSFullGCsBeforeCompaction=n CMS进行n次full gc后进行一次压缩。如果n=0,每次full gc后都会进行碎片压缩

CMS需要更多的内存,一方面是碎片问题,另一方面是对老年代回收不是在老年代满的时候,而是当老年代内存达到一定比例。
-XX:CMSIntiatingOccupancyFractio=n 当老年代内存使用达到n%,开始会后 jdk5 默认是68% 


Monitoring GC Duration & Frequency

通过ps或jps命令找到pid后,使用jstat -gc命令查看,如我在服务器上看到的Home server是这样的:

 S0C    S1C    S0U    S1U      EC       EU        OC         OU       PC     PU    YGC     YGCT    FGC    FGCT     GCT   
4032.0 1152.0  0.0   1127.2 546048.0 228879.1 4233408.0  3880211.0  70848.0 70531.1 134887 3342.336  216  1091.770 4434.107

启动了12天,花1小时多一点进行gc,总数上还可以.


Tim Yang blog上的文章比较简洁:http://timyang.net/tag/gc/

Get more control of your applications performances in development and production and know how to meet your Service Level Agreement on critical microservices. Key FeaturesLearn how to write a JavaEE application with performance constraints (Service Level Agreement-SLA) leveraging the platformLearn how to identify bottlenecks and hotspots in your application to fix themEnsure that you are able to continuously control your performance in production and during developmentBook Description The ease with which we write applications has been increasing, but with this comes the need to address their performance. A balancing act between easily implementing complex applications and keeping their performance optimal is a present-day need. In this book, we explore how to achieve this crucial balance while developing and deploying applications with Java EE 8. The book starts by analyzing various Java EE specifications to identify those potentially affecting performance adversely. Then, we move on to monitoring techniques that enable us to identify performance bottlenecks and optimize performance metrics. Next, we look at techniques that help us achieve high performance: memory optimization, concurrency, multi-threading, scaling, and caching. We also look at fault tolerance solutions and the importance of logging. Lastly, you will learn to benchmark your application and also implement solutions for continuous performance evaluation. By the end of the book, you will have gained insights into various techniques and solutions that will help create high-performance applications in the Java EE 8 environment. What you will learnIdentify performance bottlenecks in an applicationLocate application hotspots using performance toolsUnderstand the work done under the hood by EE containers and its impact on performanceIdentify common patterns to integrate with Java EE applicationsImplement transparent caching on your applicationsExtract more information from your applications using Java EE without modifying existing codeEnsure constant performance and eliminate regressionWho This Book Is For If you're a Java developer looking to improve the performance of your code or simply wanting to take your skills up to the next level, then this book is perfect for you. Table of ContentsMoney! The quote manager applicationLook under the cover : what is this "EE" thing?Monitor your applicationsApplication optimization: memory management and server configurationScale up: threading and implicationsBe lazy, cache your dataBe fault tolerantLoggers and performances: a trade-offBenching your applicationContinuous performance evaluation
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值