Original post address: http://arbow.javaeye.com/blog/362861
As boss saw a jvm gc adjustment article, he started a tuning experience as he was excited to tune our services.
Because the service belongs to a non-Background computing type, the parallel recovery policy is abandoned, while concurrent recovery is used to perform parallel recovery for the young generation, and concurrent recovery for the old generation. Parameter
Reference-xms2048m-xmx2048m-xmn512m-XX: parallelgcthreads = 8-XX: + useconcmarksweepgc-xloggc:/home/resin/logs/GC. Log
This configuration is relatively large for the young generation, with 512 m, but the problem is not found here. Using jstat for statistics, we found that almost all full
GC is completed in less than ms, but check GC. Log, it is found that the full GC is in a few seconds, the number is not large. This GC
Data in log and jstat cannot be matched. What's worse, during peak hours, fullgc is quite frequent due to the heavy occupation of the heap (suspected Memory leakage) and ou to more than 90%.
Up to 7 s of pauses. Boss was in a panic and worried after hearing it for 7 s. He thought that if fullgc is performed every 7 s and every minute, the system would have to stop for more than 10% of the time ~~
Well, when this problem occurs, someone will first think about Java
The performance is really bad. Some people want to change the JVM, and some people want to rewrite it with C ++.
Stop! This is a blind behavior. Let's analyze the problem.
1. The lack of detailed logs is too important for optimization.
2. The number of data samples is too small. The service only runs for a few days and there are no detailed records. data must be recorded.
3. Using the CMS recycler, but there are several records with a long pause time, why?
Processing:
First, more detailed log output is added.
Reference-XX: + printgcapplicationstoppedtime-XX: + printgctimestamps-XX: + printgcdetails
Sample Data and record the jstat-gcutil result to the log. The interval is ms and the record is one week.
Concurrent mode failure: When CMS is recycled concurrently, if the memory to be allocated is insufficient, the stop all
World, for a large recovery, it is very likely that when the old generation is full. In addition, the use of CMS to recycle memory fragments may also cause fragmentation problems after running for a period of time.
Do not perform a complete GC. Add Parameters
Reference-XX: + usecmscompactatfullcollection-XX: cmsinitiatingoccupancyfraction = 80
Set to compress memory fragments for each recycle, and recycle immediately when the usage rate reaches 80% in the old generation.
Finally, set the parameter
Reference-xms2048m
-Xmx2048m-xmn384m-xss256k-XX: permsize = 128 M-XX: newsize = 384 m
-XX: maxnewsize = 384 M-XX: maxpermsize = 256 m-XX: parallelgcthreads = 8
-XX: + useconcmarksweepgc-XX: + usecmscompactatfullcollection
-XX: + cmsparallelremarkenabled-XX: cmsinitiatingoccupancyfraction = 80
-XX: + printgcapplicationstoppedtime-XX: + printgctimestamps
-XX: + printgcdetails-xloggc:/home/resin/logs/GC. Log
After a week's observation, there are several points worth noting.
1. When the system is idle, fullgc takes place for a long time. In this case, the occupation of the old generation is not 80%, and the interval is very close to one hour. Log output is similar
Reference 9654.793: [full GC (system) 9654.793: [CMS: 1285124 K-> 512456 K (1703936 K), 2.9613390 secs] 1340458 K-> 512456 K (2057856 K ), [c
MS perm: 98053 K-> 81932 K (155480 K)], 2.9617070 secs] [times: User = 2.94 sys = 0.01, real = 2.96 secs]
2. When the system has a certain load, cms gc will be performed immediately when the old generation occupies 80%. The time is generally very short and will be paused twice. Log output is similar
Reference 6047.709: [GC [1 CMS-Initial-MARK: 869803 K (1703936 K)] 909529 K (2057856 K), 0.0352070 secs] [times: User = 0.04 sys = 0.00, rea
L = 0.03 secs]
6047.745: [CMS-Concurrent-mark-start]
6048.475: [CMS-Concurrent-MARK: 0.713/0.730 secs] [times: User = 1.64 sys = 0.02, real = 0.73 secs]
6048.475: [CMS-Concurrent-preclean-start]
6048.486: [CMS-Concurrent-preclean: 0.010/0.011 secs] [times: User = 0.01 sys = 0.00, real = 0.01 secs]
6048.486: [CMS-Concurrent-abortable-preclean-start]
CMS: Abort preclean due to time 6053.533: [CMS-Concurrent-abortable-preclean: 2.835/5.047 secs] [times: User = 3.52 sys = 0
. 05, real = 5.05 secs]
6053.533: [GC [YG occupancy: 205354 K (353920 K)] 6053.533: [rescan (parallel), 0.1636670 secs] 6053.697: [Weak refs proce
Ssing, 0.2716410 secs] [1 CMS-remark: 869803 K (1703936 K)] 1075158 K (2057856 K), 0.4361030 secs] [times: User = 0.57 sys = 0.28,
Real = 0.44 secs]
6053.970: [CMS-Concurrent-sweep-start]
6054.791: [CMS-Concurrent-sweep: 0.810/0.821 secs] [times: User = 0.99 sys = 0.01, real = 0.82 secs]
6054.791: [CMS-Concurrent-reset-start]
6054.802: [CMS-Concurrent-Reset: 0.010/0.010 secs] [times: User = 0.01 sys = 0.00, real = 0.01 secs]
3. Using jmap-histo for output may cause a fullgc, And the pause may exceed 8 s! Do not perform this operation during peak hours. Only jstat is used.
4. sample data analysis. The FGC time output by jstat is analyzed and categorized by small time periods. The results are as follows:
Reference time, total times, average pause time
03248.0ms5955.0508474576ms
12103.0ms3658.4166666667ms
22.163920.ms20561.95ms
320596.0ms161287.25ms
431261.0ms142232.92857143ms
536141.0ms142581.5ms
637914.0ms142472.42857143ms
723626213ms191243.47213421ms
814499.0ms31467.709677419ms
910341.0ms59175.271186441ms
1011063.0ms95116.452631579ms
118086.0ms11371.5575221239ms
1216305.0ms142132.448275862ms
136952.0ms16442.3902439024ms
147079109ms17141.1096608187ms
158023.0ms19341.5699481865ms
1626697.0ms2211116800904977ms
1715841.0ms18685.1666666667ms
187092.0ms19835.81818182ms
198373.0ms21139.682464455ms
208718109ms22838.2379421053ms
218184.0ms21238.6037735849ms
226001.0ms15837.9810126582ms
235884.0ms9860213408163265ms
Note that the number of times here includes two pauses during each CMS recycle, and contains errors caused by a small number of jmap operations.
Conclusion:
1. The CMS recycler has been ideal. It can reduce the fullgc time of 1g to about 50 ms per time on average. For applications with higher real-time requirements such as VoIP, we can look forward
G1 recycler. For applications, you need to find a balance between throughput and latency. The CMS recycler, a low-latency algorithm, will cause a decrease in throughput. In addition
The usecmscompactatfullcollection parameter may cause performance degradation. Configure the appropriate
The cmsfullgcsbeforecompaction parameter may help improve performance.
2. The JVM regularly performs non-CMS fullgc when the server is idle. The average time is over 2 seconds, usually in the middle of the night. At the time of recovery, the old generation was not yet reached
Cmsinitiatingoccupancyfraction. However, this phenomenon rarely happens, and will not occur when the server is busy, which will not have a great impact on the service.
3. for Java
For the GC of this shared heap, 2 GB is already difficult. Generally, 1 GB is an ideal size. It is right to use server resources as much as possible by using multi-JVM process clusters. (You cannot imagine what will happen when you open a 8 GB heap)
Next, adjust the JVM parameters to observe the effect.