Reputation: 1513
I use 2G new age memory before, I saw the minor gc happens every 10 seconds and takes 0.1-0.15 second each time, I want to reduce minor gc frequency so I set new age memory to 3G. After that minor gc happens every 15 seconds, but however it takes about 0.3 second to complete. Why minor GC time increase when I increase new age memory? I noticed that after I increase memory, active object after GC increase from 55M to 80M, what is the reason?
Upvotes: 0
Views: 1463
Reputation: 533530
If you want to increase the time between young collections, you want to increase the Eden size. When you change the young generation size you are likely to be also changing two things, the size of the survivor spaces and the tenuring threshold. The tenuring theshold determine how many times objects are copied back and forth between survivor spaces before being promoted to the tenured space. The default tenuring threshold is 4 but certain parameters such as -Xmn
change the tenuring threshold to 15, unless you also specify it.
You can increase the Eden space by setting the -XX:SurvivorRatio=8
form example and limit the tenuring theshold to say -XX:MaxTenuringThreshold=4
The downside of limiting the tenuring threshold is that more object will be promoted to tenuring space, which places pressure on your Full GC.
Before attempting to tenure your GC, I always recommend you do a memory profile looking at allocation e.g. with Flight Recorder. Often I find you can reduce your garbage rate by 2-4x and this will make tuning your application much easier.
Upvotes: 1
Reputation: 200168
The reason is, there are more live objects in the larger memory region. GC time primarily scales with the number (and overall size) of live objects that have to be copied to the survivor region.
You can profit from a larger young generation region only if you create many objects that all live at the same time and don't fully fit into YG. That forces them to be tenured into the Old Generation.
Otherwise the total GC time stays the same and you just choose how to split it into individual stop-the-world events: longer and less frequent or shorter and more frequent.
Upvotes: 4