锁定老帖子 主题:优化JVM参数提升Eclipse运行速度
该帖已经被评为隐藏帖
|
|||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
作者 | 正文 | ||||||||||||||||
发表时间:2011-11-07
首先建立评估体系,将workspace里所有的项目close掉,关闭eclipse。优化的用例就是启动eclipse,open一个项目,eclipse会自动build这个项目,保证没有感觉到明显的卡,也就是没有full GC。
开始:
这样eclipse在运行过程中会记录gc日志,显示详细的gc情况,并打印在gc.log中,通过分析这个日志寻找eclipse的性能瓶颈和优化方式。
将堆初始化和最大值设为一样,消除堆大小根据当前堆使用情况而变化带来的影响。
引用
4.226: [Full GC 4.226: [Tenured: 18470K->19304K(30544K), 0.1159544
secs] 25154K->19304K(44368K), [Perm : 24574K->24554K(24576K)],
0.1160431 secs] [Times: user=0.13 sys=0.00, real=0.13 secs]
在启动的6秒多时间里共出现了8次full gc,所以启动慢,觉得启动时候挺卡的。从日志里可以看出来 FullGC主要是在回收tenured区和Perm区,其中Perm一直都是快满的状态,Perm : 24574K->24554K(24576K),Perm大小在不断调整,所以需要固定Perm区的大小,保证够用,eclipse.ini里加 入
再启动:发现没有full gc了只有数量比较多的minor gc,挑启动开始到启动完成的第一条和最后一条日志
引用
0.209: [GC 0.209: [DefNew: 4416K->511K(4928K), 0.0034707 secs]
4416K->614K(15872K), 0.0035239 secs] [Times: user=0.00 sys=0.00,
real=0.00 secs]
…. 6.383: [GC 6.383: [DefNew: 18880K->1985K(21184K), 0.0055311 secs] 46992K->30098K(68040K), 0.0055694 secs]
这6秒中GC日志打了69次, 而内存回收率还是蛮高的 young区18880-1985=16895 jvm 46992-30098=16894 都快接近100%了,可以看出young区是由小到大在不断调整大小,所以不断GC,因此设一个初始值吧,据说设置heap的1/4比较好,那就是 128M,所以eclipse.ini加入
再重启,发现GC日志就四条了,eclipse启动自然快了
引用
1.292: [GC 1.292: [DefNew: 104960K->10984K(118016K), 0.0334165 secs]
104960K->10984K(511232K), 0.0334603 secs] [Times: user=0.03
sys=0.00, real=0.03 secs]
2.182: [GC 2.182: [DefNew: 115944K->1852K(118016K), 0.0221714 secs] 115944K->11466K(511232K), 0.0222142 secs] [Times: user=0.00 sys=0.02, real=0.02 secs] 3.987: [GC 3.987: [DefNew: 106779K->12531K(118016K), 0.0378228 secs] 116393K->22145K(511232K), 0.0378692 secs] [Times: user=0.03 sys=0.00, real=0.03 secs] 5.377: [GC 5.377: [DefNew: 117491K->9403K(118016K), 0.0513728 secs] 127105K->31364K(511232K), 0.0514133 secs] 但是,启动后open我的多个项目,这些项目互相依赖,eclipse自动build,感觉有点小卡,发现日志里多了4次full GC,所以就卡了…
引用
67.320: [Full GC (System) 67.320: [Tenured: 88847K->68809K(393216K),
0.2121213 secs] 117385K->68809K(511232K), [Perm :
41915K->41915K(65536K)], 0.2121747 secs] [Times: user=0.20 sys=0.00,
real=0.20 secs]
103.759: [Full GC (System) 103.759: [Tenured: 81882K->66784K(393216K), 0.3287387 secs] 185350K->66784K(511232K), [Perm : 53464K->53414K(65536K)], 0.3287897 secs] [Times: user=0.33 sys=0.00, real=0.33 secs]
这个时候Tenured区和Perm都还没到很接近最大值,但是为什么还有full
GC呢,开始以为是JVM悲观认为Tenured区剩余空间不足以应对下一次minor GC 所以进行了full
GC调整Tenured空间,索性直接增加了堆最大值到-Xmx728m(工作电脑的内存是3.5G),但重启后full
gc还是有4次,而且有几次minor
GC用的时间超过了0.1秒,这是因为增加了堆大小,导致GC用时也增加了,不能接受。所以还是改回-Xmx512m。
这样就差不多了,整个过程没有出现full gc,再编码2个小时,中间只出现了一次full gc,在open build某50W行+的代码的时候,eclipse还是卡了…
另外没有去调GC策略,主要是觉得eclipse是客户端程序,默认的client单线程的GC策略应该是比较适合的,以后有时间再试试看吧。 Java 虚拟机默认分配64M内存,如果你的应用比较大,超出64M内 存,Java虚拟机就会抛出outOfMemoryError,并停止运行。不管是什么应用(Web应用、Application等),只需要修改你的机 器上的运行Java命令,在javaxxx命令中添加-Xms(最小使用内存)、-Xmx(最大使用内存)即可解决。当然,这儿的内存容量都是指物理内 存,不能超出你的机器的物理内存的总容量。
对于单独的.class,可以用下面的方法对Test运行时的jvm内存进行设置。 在eclipse中的设置方法 方 法1:对应在Eclipse中的设置为:窗口->首选项->JAVA->已安装的JRE,在缺 省的VM自变量中增加:-Xmx256M (也可以添加其他参数如-Xms128M -XX:PermSize=64M -XX:MaxPermSize=128M)
方法2:修改eclipse.ini
C:\Java\jre1.6.0\bin\javaw.exe 摘自:http://16.199.geisvps.com/blog/v/23084.html <!--EndFragment-->
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|||||||||||||||||
返回顶楼 | |||||||||||||||||
发表时间:2011-11-08
最后修改:2011-11-08
文章中分析的很到位,这么好的文章为什么没有人顶呢?
说说我的情况: 我之前给MyEclispe的参数:
-vmargs -Xmx600m -Xms600m -XX:NewSize=200m -XX:MaxNewSize=200m -XX:SurvivorRatio=8 -XX:PermSize=150m -XX:MaxPermSize=300m -XX:ReservedCodeCacheSize=64m 这个参数让装了有快有一年的Myeclipse8.5从之前的启动需要1分多种减少到15s内。 启动速度确实上来了,但是在使用MyEclipse的时候感觉还是有点小卡(CPU intel 奔腾双核 1.86GHz) 这次按文章中的方法加上下面这些参数:
-XX:+PrintGCTimeStamps -XX:+PrintGCDetails -verbose:gc -Xloggc:gc.log 之后,除了打开工程,没有对MyEclipse做任何操作,半个小时候查看gc.log的结果:
11.701: [GC 11.701: [DefNew: 163840K->17664K(184320K), 0.1308610 secs] 163840K->17664K(593920K), 0.1310281 secs] [Times: user=0.13 sys=0.00, real=0.14 secs] 33.276: [GC 33.276: [DefNew: 181504K->20480K(184320K), 0.2041340 secs] 181504K->44518K(593920K), 0.2043061 secs] [Times: user=0.17 sys=0.03, real=0.20 secs] 55.985: [GC 55.985: [DefNew: 184320K->9338K(184320K), 0.1380530 secs] 208358K->53702K(593920K), 0.1382198 secs] [Times: user=0.13 sys=0.02, real=0.14 secs] 81.138: [GC 81.138: [DefNew: 173178K->20480K(184320K), 0.1468986 secs] 217542K->68031K(593920K), 0.1471215 secs] [Times: user=0.16 sys=0.00, real=0.16 secs] 114.620: [GC 114.621: [DefNew: 184320K->7770K(184320K), 0.1289499 secs] 231871K->75531K(593920K), 0.1291904 secs] [Times: user=0.13 sys=0.00, real=0.13 secs] 124.253: [GC 124.254: [DefNew: 171610K->11985K(184320K), 0.0722709 secs] 239371K->79746K(593920K), 0.0724039 secs] [Times: user=0.06 sys=0.00, real=0.06 secs] 142.045: [Full GC (System) 142.046: [Tenured: 67761K->86645K(409600K), 0.8119912 secs] 239878K->86645K(593920K), [Perm : 85066K->85066K(153600K)], 0.8121247 secs] [Times: user=0.80 sys=0.01, real=0.81 secs] 263.956: [Full GC (System) 263.956: [Tenured: 86645K->92069K(409600K), 0.7481820 secs] 243819K->92069K(593920K), [Perm : 89906K->89906K(153600K)], 0.7483133 secs] [Times: user=0.72 sys=0.02, real=0.75 secs] 281.199: [GC 281.200: [DefNew: 163840K->13688K(184320K), 0.0767349 secs] 255909K->105757K(593920K), 0.0768578 secs] [Times: user=0.08 sys=0.00, real=0.08 secs] 284.581: [GC 284.581: [DefNew: 177528K->12871K(184320K), 0.0820026 secs] 269597K->110799K(593920K), 0.0821920 secs] [Times: user=0.09 sys=0.01, real=0.09 secs] 286.116: [GC 286.116: [DefNew: 176711K->7399K(184320K), 0.0668479 secs] 274639K->112967K(593920K), 0.0669781 secs] [Times: user=0.06 sys=0.00, real=0.06 secs] 286.228: [Full GC (System) 286.228: [Tenured: 105567K->111235K(409600K), 0.8151195 secs] 115825K->111235K(593920K), [Perm : 91780K->91780K(153600K)], 0.8152469 secs] [Times: user=0.80 sys=0.01, real=0.81 secs] 292.912: [GC 292.912: [DefNew: 163840K->20480K(184320K), 0.0989793 secs] 275075K->133752K(593920K), 0.0991073 secs] [Times: user=0.09 sys=0.00, real=0.11 secs] 294.484: [Full GC (System) 294.485: [Tenured: 113272K->80468K(409600K), 1.0058385 secs] 163505K->80468K(593920K), [Perm : 91784K->91652K(153600K)], 1.0059614 secs] [Times: user=0.97 sys=0.00, real=1.00 secs] 301.693: [GC 301.693: [DefNew: 163840K->1169K(184320K), 0.0133009 secs] 244308K->81637K(593920K), 0.0134092 secs] [Times: user=0.02 sys=0.00, real=0.02 secs] 306.183: [GC 306.184: [DefNew: 165009K->6633K(184320K), 0.0357372 secs] 245477K->87101K(593920K), 0.0358512 secs] [Times: user=0.03 sys=0.00, real=0.03 secs] 306.608: [Full GC (System) 306.608: [Tenured: 80468K->83381K(409600K), 0.7501445 secs] 108924K->83381K(593920K), [Perm : 92555K->92555K(153600K)], 0.7502719 secs] [Times: user=0.75 sys=0.00, real=0.75 secs] 310.657: [Full GC (System) 310.657: [Tenured: 83381K->83454K(409600K), 0.7835300 secs] 214430K->83454K(593920K), [Perm : 92556K->92556K(153600K)], 0.7836516 secs] [Times: user=0.75 sys=0.03, real=0.78 secs] 317.094: [GC 317.094: [DefNew: 163840K->5984K(184320K), 0.0407806 secs] 247294K->89439K(593920K), 0.0409139 secs] [Times: user=0.05 sys=0.00, real=0.05 secs] 317.866: [Full GC (System) 317.866: [Tenured: 83454K->86193K(409600K), 0.7915970 secs] 120290K->86193K(593920K), [Perm : 94212K->94212K(153600K)], 0.7917076 secs] [Times: user=0.80 sys=0.00, real=0.80 secs] 324.970: [GC 324.970: [DefNew: 163840K->5257K(184320K), 0.0358755 secs] 250033K->91451K(593920K), 0.0360118 secs] [Times: user=0.03 sys=0.00, real=0.03 secs] 327.701: [GC 327.701: [DefNew: 169097K->7010K(184320K), 0.0264821 secs] 255291K->93203K(593920K), 0.0265975 secs] [Times: user=0.03 sys=0.00, real=0.03 secs] 359.885: [GC 359.885: [DefNew: 170850K->10573K(184320K), 0.0364652 secs] 257043K->96767K(593920K), 0.0365868 secs] [Times: user=0.03 sys=0.00, real=0.03 secs] 369.894: [GC 369.894: [DefNew: 174413K->2319K(184320K), 0.0251560 secs] 260607K->91151K(593920K), 0.0253669 secs] [Times: user=0.03 sys=0.00, real=0.03 secs] 403.328: [Full GC (System) 403.328: [Tenured: 88832K->80105K(409600K), 1.0220704 secs] 161545K->80105K(593920K), [Perm : 98768K->98731K(153600K)], 1.0222006 secs] [Times: user=0.97 sys=0.00, real=1.02 secs] 466.072: [Full GC (System) 466.073: [Tenured: 80105K->80642K(409600K), 0.8000235 secs] 106328K->80642K(593920K), [Perm : 99063K->99063K(153600K)], 0.8001601 secs] [Times: user=0.78 sys=0.00, real=0.80 secs] 526.074: [Full GC (System) 526.074: [Tenured: 80642K->80683K(409600K), 0.8330606 secs] 96886K->80683K(593920K), [Perm : 99080K->99080K(153600K)], 0.8331808 secs] [Times: user=0.80 sys=0.01, real=0.83 secs] 586.076: [Full GC (System) 586.076: [Tenured: 80683K->80684K(409600K), 0.8552643 secs] 92980K->80684K(593920K), [Perm : 99081K->99081K(153600K)], 0.8553981 secs] [Times: user=0.83 sys=0.02, real=0.84 secs] 654.626: [Full GC (System) 654.626: [Tenured: 80684K->83238K(409600K), 1.0774936 secs] 216608K->83238K(593920K), [Perm : 99675K->98327K(153600K)], 1.0776509 secs] [Times: user=1.06 sys=0.00, real=1.08 secs] 719.316: [Full GC (System) 719.316: [Tenured: 83238K->83239K(409600K), 0.7805811 secs] 96784K->83239K(593920K), [Perm : 98329K->98329K(153600K)], 0.7806964 secs] [Times: user=0.78 sys=0.00, real=0.78 secs] 779.319: [Full GC (System) 779.319: [Tenured: 83239K->83240K(409600K), 0.7695637 secs] 94848K->83240K(593920K), [Perm : 98332K->98332K(153600K)], 0.7696785 secs] [Times: user=0.77 sys=0.00, real=0.77 secs] 839.320: [Full GC (System) 839.320: [Tenured: 83240K->83241K(409600K), 1.0636681 secs] 94851K->83241K(593920K), [Perm : 98333K->98333K(153600K)], 1.0637813 secs] [Times: user=0.99 sys=0.02, real=1.06 secs] 903.050: [Full GC (System) 903.051: [Tenured: 83241K->81216K(409600K), 1.0320834 secs] 96172K->81216K(593920K), [Perm : 98334K->98168K(153600K)], 1.0322153 secs] [Times: user=1.03 sys=0.00, real=1.03 secs] 964.926: [Full GC (System) 964.926: [Tenured: 81216K->81219K(409600K), 0.8225657 secs] 94942K->81219K(593920K), [Perm : 98169K->98169K(153600K)], 0.8226948 secs] [Times: user=0.81 sys=0.00, real=0.81 secs] 1024.927: [Full GC (System) 1024.927: [Tenured: 81219K->81238K(409600K), 0.7834102 secs] 93686K->81238K(593920K), [Perm : 98171K->98171K(153600K)], 0.7835351 secs] [Times: user=0.76 sys=0.01, real=0.78 secs] 1084.928: [Full GC (System) 1084.928: [Tenured: 81238K->81256K(409600K), 0.7659853 secs] 93269K->81256K(593920K), [Perm : 98172K->98172K(153600K)], 0.7661144 secs] [Times: user=0.76 sys=0.00, real=0.77 secs] 1144.930: [Full GC (System) 1144.930: [Tenured: 81256K->80665K(409600K), 0.9554295 secs] 93290K->80665K(593920K), [Perm : 98173K->98035K(153600K)], 0.9555525 secs] [Times: user=0.95 sys=0.00, real=0.95 secs] 1204.939: [Full GC (System) 1204.939: [Tenured: 80665K->80666K(409600K), 0.7792535 secs] 95977K->80666K(593920K), [Perm : 98037K->98037K(153600K)], 0.7793979 secs] [Times: user=0.76 sys=0.00, real=0.78 secs] 1264.931: [Full GC (System) 1264.931: [Tenured: 80666K->80668K(409600K), 0.7703641 secs] 92699K->80668K(593920K), [Perm : 98040K->98040K(153600K)], 0.7704859 secs] [Times: user=0.77 sys=0.00, real=0.77 secs] 1324.935: [Full GC (System) 1324.935: [Tenured: 80668K->80670K(409600K), 0.7892472 secs] 93283K->80670K(593920K), [Perm : 98042K->98042K(153600K)], 0.7893771 secs] [Times: user=0.76 sys=0.00, real=0.78 secs] 1384.933: [Full GC (System) 1384.933: [Tenured: 80670K->70628K(409600K), 0.9313876 secs] 92686K->70628K(593920K), [Perm : 98043K->97988K(153600K)], 0.9315156 secs] [Times: user=0.91 sys=0.01, real=0.92 secs] 1444.939: [Full GC (System) 1444.940: [Tenured: 70628K->70630K(409600K), 0.7289678 secs] 82649K->70630K(593920K), [Perm : 97990K->97990K(153600K)], 0.7290960 secs] [Times: user=0.73 sys=0.00, real=0.73 secs] 1504.936: [Full GC (System) 1504.936: [Tenured: 70630K->70631K(409600K), 0.7613951 secs] 85934K->70631K(593920K), [Perm : 97991K->97991K(153600K)], 0.7615233 secs] [Times: user=0.74 sys=0.00, real=0.75 secs] 1564.939: [Full GC (System) 1564.939: [Tenured: 70631K->70650K(409600K), 0.7673632 secs] 82330K->70650K(593920K), [Perm : 97993K->97993K(153600K)], 0.7676210 secs] [Times: user=0.73 sys=0.00, real=0.77 secs] 1624.939: [Full GC (System) 1624.940: [Tenured: 70650K->70611K(409600K), 0.9317989 secs] 82762K->70611K(593920K), [Perm : 97994K->97981K(153600K)], 0.9319184 secs] [Times: user=0.92 sys=0.00, real=0.92 secs] 1684.939: [Full GC (System) 1684.939: [Tenured: 70611K->70613K(409600K), 0.7297785 secs] 82308K->70613K(593920K), [Perm : 97983K->97983K(153600K)], 0.7299137 secs] [Times: user=0.72 sys=0.00, real=0.72 secs] 1744.939: [Full GC (System) 1744.939: [Tenured: 70613K->70631K(409600K), 0.7611817 secs] 82329K->70631K(593920K), [Perm : 97984K->97984K(153600K)], 0.7612984 secs] [Times: user=0.73 sys=0.00, real=0.75 secs] 1804.940: [Full GC (System) 1804.940: [Tenured: 70631K->70632K(409600K), 0.7399742 secs] 85078K->70632K(593920K), [Perm : 97985K->97985K(153600K)], 0.7400913 secs] [Times: user=0.73 sys=0.00, real=0.73 secs] 1864.941: [Full GC (System) 1864.941: [Tenured: 70632K->70610K(409600K), 0.7513569 secs] 81497K->70610K(593920K), [Perm : 97986K->97981K(153600K)], 0.7514908 secs] [Times: user=0.75 sys=0.00, real=0.75 secs] 1924.942: [Full GC (System) 1924.942: [Tenured: 70610K->70611K(409600K), 0.7210821 secs] 81885K->70611K(593920K), [Perm : 97982K->97982K(153600K)], 0.7212017 secs] [Times: user=0.72 sys=0.00, real=0.72 secs] 1984.946: [Full GC (System) 1984.946: [Tenured: 70611K->70612K(409600K), 0.7335494 secs] 81254K->70612K(593920K), [Perm : 97984K->97984K(153600K)], 0.7336891 secs] [Times: user=0.72 sys=0.00, real=0.73 secs] 2044.944: [Full GC (System) 2044.944: [Tenured: 70612K->70613K(409600K), 0.7208335 secs] 81662K->70613K(593920K), [Perm : 97985K->97985K(153600K)], 0.7209497 secs] [Times: user=0.72 sys=0.00, real=0.72 secs] 2116.028: [Full GC (System) 2116.028: [Tenured: 70613K->71149K(409600K), 1.0785044 secs] 91193K->71149K(593920K), [Perm : 98074K->98069K(153600K)], 1.0786446 secs] [Times: user=1.05 sys=0.02, real=1.08 secs] 2180.716: [Full GC (System) 2180.716: [Tenured: 71149K->71242K(409600K), 0.7651774 secs] 101433K->71242K(593920K), [Perm : 98106K->98106K(153600K)], 0.7652953 secs] [Times: user=0.75 sys=0.00, real=0.77 secs] 2240.713: [Full GC (System) 2240.713: [Tenured: 71242K->71261K(409600K), 0.7011372 secs] 83695K->71261K(593920K), [Perm : 98108K->98108K(153600K)], 0.7012467 secs] [Times: user=0.69 sys=0.00, real=0.69 secs] 2300.714: [Full GC (System) 2300.714: [Tenured: 71261K->71271K(409600K), 0.7156552 secs] 88608K->71271K(593920K), [Perm : 98110K->98110K(153600K)], 0.7157812 secs] [Times: user=0.70 sys=0.00, real=0.70 secs] 2360.715: [Full GC (System) 2360.715: [Tenured: 71271K->62842K(409600K), 0.8110805 secs] 83015K->62842K(593920K), [Perm : 98112K->98106K(153600K)], 0.8111956 secs] [Times: user=0.80 sys=0.00, real=0.81 secs] 2420.716: [Full GC (System) 2420.716: [Tenured: 62842K->62865K(409600K), 0.7358391 secs] 78283K->62865K(593920K), [Perm : 98108K->98108K(153600K)], 0.7359491 secs] [Times: user=0.74 sys=0.00, real=0.73 secs] 2480.723: [Full GC (System) 2480.723: [Tenured: 62865K->62884K(409600K), 0.7648589 secs] 75194K->62884K(593920K), [Perm : 98109K->98109K(153600K)], 0.7649740 secs]
可以看得出Full GC (System) 相当的多,也很耗时..
加上 -XX:+DisableExplicitGC 参数后,没有明显的卡顿了,还是量身定做的参数效果好。
|
|||||||||||||||||
返回顶楼 | |||||||||||||||||
发表时间:2011-11-08
竟然19个投隐藏贴的,郁闷死。
iteye什么时候这样了? |
|||||||||||||||||
返回顶楼 | |||||||||||||||||
浏览 4315 次