浅析配置更快的Eclipse方法
很多人感觉自己的elipse启动比较慢,其实并不是因为装的插件太多或者是导入的项目有点大,而是因为参数的设置不合理导致的。可以在eclipse.ini里面添加
-Xloggc:gc.log看看启动的日志。下面简单的说一下通过优化一下配置来节约eclipse的启动时间,文中的数据是我本机的环境,我本机内存为3.16G。
第一次优化:把-Xms(初始化堆大小)-Xmx(JVM最大堆大小)设置为512m,避免频繁GC。如下所示:
-Xms512m
-Xmx512m
-verbose:gc
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-Xloggc:gc.log
重启eclipse的时候Full GC的次数为8次,minitor GC的次数为3。日志如下:
2014-06-09T20:39:00.480+0800: 1.850: [GC 1.850: [DefNew: 139776K->17472K(157248K), 0.0613123 secs] 139776K->20106K(506816K), 0.0614226 secs] [Times: user=0.06 sys=0.00, real=0.06 secs]
2014-06-09T20:39:01.214+0800: 2.597: [Full GC 2.597: [Tenured: 2634K->35922K(349568K), 0.1242231 secs] 81163K->35922K(506816K), [Perm : 16383K->16383K(16384K)], 0.1243415 secs] [Times: user=0.11 sys=0.01, real=0.13 secs]
2014-06-09T20:39:01.698+0800: 3.075: [Full GC 3.075: [Tenured: 35922K->38486K(349568K), 0.1086032 secs] 121915K->38486K(506816K), [Perm : 20479K->20479K(20480K)], 0.1087152 secs] [Times: user=0.11 sys=0.00, real=0.11 secs]
2014-06-09T20:39:02.026+0800: 3.408: [Full GC 3.408: [Tenured: 38486K->39671K(349568K), 0.1166902 secs] 52893K->39671K(506816K), [Perm : 24575K->24575K(24576K)], 0.1168707 secs] [Times: user=0.13 sys=0.00, real=0.13 secs]
2014-06-09T20:39:02.558+0800: 3.926: [Full GC 3.926: [Tenured: 39671K->41312K(349568K), 0.1572323 secs] 57131K->41312K(506816K), [Perm : 28671K->28650K(28672K)], 0.1573102 secs] [Times: user=0.16 sys=0.00, real=0.16 secs]
2014-06-09T20:39:03.276+0800: 4.653: [Full GC 4.653: [Tenured: 41312K->44308K(349568K), 0.1656481 secs] 87405K->44308K(506816K), [Perm : 32767K->32767K(32768K)], 0.1657328 secs] [Times: user=0.17 sys=0.00, real=0.17 secs]
2014-06-09T20:39:04.058+0800: 5.439: [GC 5.439: [DefNew: 139776K->17472K(157248K), 0.0356182 secs] 184084K->62657K(506816K), 0.0357149 secs] [Times: user=0.05 sys=0.00, real=0.05 secs]
2014-06-09T20:39:04.105+0800: 5.475: [GC 5.475: [DefNew: 19934K->7K(157248K), 0.0245383 secs] 65119K->62662K(506816K), 0.0246034 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
2014-06-09T20:39:04.136+0800: 5.507: [Full GC 5.507: [Tenured: 62654K->62672K(349568K), 0.1803366 secs] 68235K->62672K(506816K), [Perm : 36863K->36863K(36864K)], 0.1804263 secs] [Times: user=0.17 sys=0.00, real=0.17 secs]
2014-06-09T20:39:04.839+0800: 6.215: [Full GC 6.215: [Tenured: 62672K->64003K(349568K), 0.2267431 secs] 198067K->64003K(506816K), [Perm : 40959K->40959K(40960K)], 0.2268157 secs] [Times: user=0.23 sys=0.00, real=0.23 secs]
2014-06-09T20:39:06.417+0800: 7.796: [Full GC 7.796: [Tenured: 64003K->71144K(349568K), 0.3148881 secs] 182608K->71144K(506816K), [Perm : 45055K->45035K(45056K)], 0.3149710 secs]
从日志中分析可以看出:触发Full GC的罪魁祸首是Perm,这个没有设置,所以应该继续优化!
第二次优化:把持久化的初始化大小和最大大小设置为512m。如下所示:
-Xms512m
-Xmx512m
-XX:PermSize=512m
-XX:MaxPermSize=512m
-verbose:gc
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-Xloggc:gc.log
2014-06-09T20:43:29.442+0800: 1.872: [GC 1.872: [DefNew: 139776K->17472K(157248K), 0.0614285 secs] 139776K->20106K(506816K), 0.0615441 secs] [Times: user=0.06 sys=0.00, real=0.06 secs]
2014-06-09T20:43:30.426+0800: 2.852: [GC 2.852: [DefNew: 157248K->17472K(157248K), 0.0714705 secs] 159882K->37813K(506816K), 0.0715851 secs] [Times: user=0.06 sys=0.02, real=0.08 secs]
2014-06-09T20:43:32.176+0800: 4.608: [GC 4.608: [DefNew: 157248K->17472K(157248K), 0.0846898 secs] 177589K->59609K(506816K), 0.0848035 secs] [Times: user=0.09 sys=0.00, real=0.09 secs]
2014-06-09T20:43:32.676+0800: 5.099: [GC 5.099: [DefNew: 157248K->3513K(157248K), 0.0443054 secs] 199385K->63063K(506816K), 0.0444509 secs] [Times: user=0.05 sys=0.00, real=0.05 secs]
2014-06-09T20:43:33.285+0800: 5.705: [GC 5.705: [DefNew: 143289K->10365K(157248K), 0.0427973 secs] 202839K->69914K(506816K), 0.0428756 secs]
Full GC消失了,来了5次Minor GC。从日志中分析可以看出:频繁的Minor GC是由新生代没有设置自动分配造成的。
第三次优化:-Xmn256m 设置新生代大小为256M。好了,就3次Minor GC。日志如下:
2014-06-09T20:45:29.204+0800: 2.500: [GC 2.500: [DefNew: 209792K->26176K(235968K), 0.0951747 secs] 209792K->35901K(498112K), 0.0952914 secs] [Times: user=0.09 sys=0.00, real=0.09 secs]
2014-06-09T20:45:31.220+0800: 4.515: [GC 4.515: [DefNew: 235968K->22389K(235968K), 0.1084576 secs] 245693K->58147K(498112K), 0.1085766 secs] [Times: user=0.11 sys=0.00, real=0.11 secs]
2014-06-09T20:45:32.001+0800: 5.302: [GC 5.302: [DefNew: 232181K->5280K(235968K), 0.0570383 secs] 267939K->63248K(498112K), 0.0571581 secs]
最后的配置如下:
-Xmn256m
-Xms512m
-Xmx512m
-XX:PermSize=512m
-XX:MaxPermSize=512m
-verbose:gc
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-Xloggc:gc.log