Class `LostCityChunkGenerator` and Class` BuildingInfo` may have memory leak problem
CatEricka opened this issue · 8 comments
Environment
Server
Minecraft: 1.12.2
SpongeAPI: 7.1.0-fb496dbf0
Sponge: 1.12.2-7.1.6
SpongeForge: 1.12.2-2825-7.1.6
Minecraft Forge: 14.23.5.2825
JVM: 1.8.0_231/64-bit (Oracle Corporation)
OS: Linux (4.19.0-6-amd64/amd64)
JVM Arguments
java -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=100 -XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MixedGCLiveThresholdPercent=35 -XX:+AlwaysPreTouch -XX:+ParallelRefProcEnabled -XX:ParallelGCThreads=2 -Xms6G -Xmx6G -jar forge-1.12.2-14.23.5.2825-universal.jar
Mod version
State | ID | Version | Source | Signature |
---|---|---|---|---|
LCHIJA | lostcities | 2.0.21 | lostcities-1.12-2.0.21.jar | None |
LCHIJA | minecraft | 1.12.2 | minecraft.jar | None |
LCHIJA | mcp | 9.42 | minecraft.jar | None |
LCHIJA | FML | 8.0.99.99 | forge-1.12.2-14.23.5.2825-universal.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 |
LCHIJA | forge | 14.23.5.2825 | forge-1.12.2-14.23.5.2825-universal.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 |
LCHIJA | spongeapi | 7.1.0-fb496dbf0 | spongeforge-1.12.2-2825-7.1.6.jar | None |
LCHIJA | sponge | 1.12.2-7.1.6 | spongeforge-1.12.2-2825-7.1.6.jar | None |
LCHIJA | spongeforge | 1.12.2-2825-7.1.6 | spongeforge-1.12.2-2825-7.1.6.jar | None |
LCHIJA | reforged | 0.7.5 | Reforged-Mod-1.12.jar | None |
LCHIJA | baubles | 1.5.2 | Baubles-1.12-1.5.2.jar | None |
LCHIJA | bloodmoon | 1.5.3 | Bloodmoon-MC1.12.2-1.5.3.jar | d72e0dd57935b3e9476212aea0c0df352dd76291 |
LCHIJA | jei | 4.15.0.293 | jei_1.12.2-4.15.0.293.jar | None |
LCHIJA | botania | r1.10-361 | Botania+r1.10-361.jar | None |
LCHIJA | ebwizardry | 4.2.5 | ElectroblobsWizardry-4.2.5-MC1.12.2.jar | None |
LCHIJA | extrabotany | 56 | ExtraBotany-r1.1-56.jar | None |
LCHIJA | flexiblelogin | 0.18-SNAPSHOT | flexiblelogin-0.18-SNAPSHOT.jar | None |
LCHIJA | ic2 | 2.8.187-ex112 | industrialcraft-2-2.8.187-modify-V1.1.jar | de041f9f6187debbc77034a344134053277aa3b0 |
LCHIJA | infernalmobs | 1.7.5 | InfernalMobs-1.12.2.jar | None |
LCHIJA | luckperms | 4.3.75 | LuckPerms-Sponge-4.3.75.jar | None |
LCHIJA | nucleus | 1.11.0-S7.1 | Nucleus-1.11.0-S7.1-MC1.12.2-plugin.jar | None |
LCHIJA | harvestcraft | 1.12.2zb | Pam's+HarvestCraft+1.12.2zd+Surprise+.jar | None |
Problem overview
Frequent Full GC begin to occur after the server has been running for more than 10 hours and a player was flying around in a world. Check found that the old gen
usage in the JVM heap is 99% (3GB allocated for old gen
)
Details
Use jmap to capture java heap dump:
Reference chain in Leak Report:
It can be seen that cachedPrimers
and buildingInfoMap
are problematic objects, of which cachedPrimers
has reached about 1.2GB and buildingInfoMap
has reached about 1.19GB.
According to file LostCityChunkGenerator.java
:
// Sometimes we have to precalculate primers for a chunk before the
// chunk is generated. In that case we cache them here so that when the
// chunk is really generated it will find it and use that instead of
// making that primer again
// @todo, make this cache timed so that primers expire if they are not used quickly enough?
private Map<ChunkCoord, ChunkPrimer> cachedPrimers = new HashMap<>();
private Map<ChunkCoord, ChunkHeightmap> cachedHeightmaps = new HashMap<>();
Searching for references found that the used cache would only be cleared in the getChunkPrimer
method. Is it possible that cachedPrimers
will not be cleaned up in time to cause a memory leak? This may happen after frequent chunk generation.
I guess buildingInfoMap
in Class BuildingInfo
may have the same problem.
I have only tried in this environment. Maybe it is it ’s caused by sponge or other mods, I will try to reproduce the problem later. Is there anything I missed?
Configuration file:
Only modified S:defaultProfile=rarecities
and S:dimensionProfile=rarecities
You haven't missed anything. This is a cache that is not cleaned up. Only way to clean it up is to restart the world as it only happens during chunk generation. This is also why it wasn't really a big priority for me but it's something that I plan to handle
Is it feasible to change Map<ChunkCoord, ChunkPrimer>
to private Map<ChunkCoord, SoftReference<ChunkPrimer>>
or other solutions using soft references? Maybe I will try to implement cache cleanup.
Soft references are not the solution as that will remove them from the cache too soon as nothing is keeping references to it besides the cache. It really needs a timer
Thanks for your reply, I created a script to restart the server periodically to alleviate this problem :)
I'm also having similar issues on the server a friend of mine is hosting. Anytime someone is on the LC dimension for a while, the tick-lag grows and grows. Even when no one is in the LC dimension, there's still a massive tick-lag that requires restarting the server instance.
As fun as it is in that dimension, we're going to have to stop using it until this can be fixed. :-(
I'm also having similar issues on the server a friend of mine is hosting. Anytime someone is on the LC dimension for a while, the tick-lag grows and grows. Even when no one is in the LC dimension, there's still a massive tick-lag that requires restarting the server instance.
As fun as it is in that dimension, we're going to have to stop using it until this can be fixed. :-(
It may be possible to use LinkedHashMap as the LRU cache to replace the HashMap, just limit the cache size. But I am having trouble building this project.