Reprinted from: http://www.54chen.com/java-ee/jvm.html
Foundation:
business code
rose framework (the bottom layer is spring)
resin4
java 1.6.0_38-b05
centos
Initial configuration:
Only the following three values have been modified
- Xmx5000M // The size of the max heap.
-Xms5000M // The size of min's heap is the size given at the beginning. If it is not enough, it will be GC first, and if it is not enough, it will be added until max.
-Xmn2000M // The size of the young area, generally speaking: heap=Y+O, P is an additional value. Sun recommends Y=heap*(3/8).
gc情况解读:
# jstat -gcutil 20538 1000 100
S0 S1 EOP YGC YGCT FGC FGCT GCT
0.00 51.96 62.53 73.42 99.93 35830 1554.778 185 1089.488 2644.266
0.00 51.96 69.83 73.42 99.93 35830 1554.778 185 1089.488 2644.266
0.00 51.96 77.75 73.42 99.93 35830 1554.778 185 1089.488 2644.266
0.00 51.96 85.79 73.42 99.93 35830 1554.778 185 1089.488 2644.266
0.00 51.96 92.35 73.42 99.93 35830 1554.778 185 1089.488 2644.26
S0\S1 is the survivor area, which is the object that has not been dropped by the gc. It is guided back and forth in these two survivors, and finally enters the O area when the conditions are met.
E is the Eden area, E+S0+S1=Y.
According to the data of jstat, YGC occurs about every 15 seconds on this machine, and there has been no FGC for a long time (more than 1 day), and 99.93% of the P area has been used.
Interpretation of the memory status of each area:
是否需要优化判定:
YGCT/YGC=40ms 且十几秒才一次,健康
FGCT/FGC=5s 但是一天也没几次,业务允许,一般健康可优化。未来可考虑优化为多次FGC减少FGCT的时长。
后续思考:
虽然FGC并不频繁,但因为xmx值比较大,导致了O区相对变大,同时FGC缓慢,考虑从两个方向:1.调整Y区大小,让YGC去到O区的数据更少,让FGC频率更加慢(有可能很难有变化)2.调整整体的大小,让FGC频繁一点点但更加快一点 3.调整FGC的算法,让速度快一点到1秒内来。
对照组结果后续有结论了再来续本文内容。
GC优化永远是最后一项任务。