Shadows-of-Fire / ClickMachine

Clicc
MIT License
11 stars 8 forks source link

Using click machines to stock sifting material and meshes for Ex Nihilo Sequentia sieves causes memory leaks #54

Closed Daxturus closed 1 month ago

Daxturus commented 1 month ago

### Using: Minecraft 1.20.1 NeoForged version 47.1.106 ClickMachine version 1.20.1-8.0.2 Ex Nihilo Sequentia version 5.0.0-build.8

###The Issue This is mainly a serverside issue, affecting both dedicated servers and singleplayer worlds. This issue does not seem to affect clients connected to dedicated servers, at least not nearly as quickly as servers.

Using Click Machine to automatically click Ex Nihilo sieves and restock them with meshes and sifting materials seems to cause a slow but steady memory leak, causing a server to run out of memory within an hour or two. The log does not show anything interesting during this time, other than the occasional "Can't keep up!" before the server hangs.

I am not sure about the details, but using the setup and mods I have provided, a memory leak occurs, eventually resulting in a crash. It could very well be that this occurs whenever a Click Machine interacts with a Ex Nihilo sieve, but it could also be caused by using two separate Click Machines to interact with a single sieve at once, a problem which would only be specific only to my current mod configs.

###How I found out about this I am currently hosting a small server for my friends. After building an automated sifting setup using Click Machines, the server (and my computer) would occasionally hang. I noticed the game was running out of memory. I tested multiple JVM arguments to make garbage collection more aggressive (for instance, -XX:+UseG1GC), but these just tend to flatten the slow rise in memory usage. After this, I decided to do some testing to figure out the source of this issue. After a day of trial and error, I realized the Ex Nihilo setup using Click Machines we had built was the source of the memory leak.

###Steps to Reproduce 1) EITHER: Create a new 1.20.1 Minecraft world with NeoForged. Use both Ex Nihilo Sequentia and Click Machine as mods. Point two click machines into an Ex Nihilo Sieve. Use hoppers or another method of item insertion to give one click machine Ex Nihilo meshes, and the other click machine a material used for sieving (I use gravel). Power these click machines, and increase the click speed of the gravel/dirt/sand clicker to around 4 clicks per second. (This is what I have used in my testing; it is what we used on our world.) OR: Load the provided world file with Ex Nihilo Sequentia, Click Machine, Thermal Expansion, Thermal Dynamics, Thermal Foundation, Thermal Integration, and Applied Energistics 2 for item logistics; this roughly represents the setup created on our server world.

2) In either case, make sure the sieves are running properly and that they are automatically producing materials. Make sure to collect the generated materials somehow, (e.g. by using a Thermal series vacuumulator, or AE2 annihilation planes, or even using water streams leading to hoppers); lag caused by items is a separate issue which server admins or players can solve on their own. NOTE: If you decide to load the test world, you may have to replace the fluxducts; Thermal fluxducts seem to have their own issues at the moment which I cannot even begin to wrap my head around. I found that removing them with a crescent hammer, reloading the world, and replacing the fluxducts (especially ones right next to the power source) tends to fix any issues with them.

3) Press F3; there should be a Mem value in the top right corner showing the current memory usage. Watching this variable will allow you to monitor memory usage.

4) After some unknown period of time after using click machines on sieves (from five minutes to half an hour), memory usage will begin to suddenly and steadily rise. I usually see memory usage increase by at least a gigabyte within the first thirty minutes of testing, though it could vary by the amount of allocated memory or how many sieves you are using.

5) Eventually, Minecraft or a hosted Minecraft server suffering from this problem will run out of memory and hang. When joined to a server with this issue, clients will first notice stuttering lag spikes, which shortly turn to being unable to interact with tile entities, before dropping connection.

Crash Log.txt [Uploading Example Save & Mods.zip…]()

Shadows-of-Fire commented 1 month ago

Does this happen if you target the clickers at other objects? If not, it may be a bug in Ex Nihilo and how it is interacting with fake players.

Daxturus commented 1 month ago

I'll check. Also, I just realized the world and mods zip file was not uploaded correctly. I will upload it elsewhere in a bit.

Daxturus commented 1 month ago

I ran two tests: one on my server, where I moved the click machines to interact with trapdoors, and another in a Singleplayer world, where I am using Create deployers. Apparently those can also interact with Ex Nihilo sieves, -- and they too cause a memory leak in doing so (85% memory usage and rising on an empty no-mob Superflat world? Sounds like a memory leak) On the server where the click machines are interacting with trapdoors, however, memory usage is hovering around 2.5 GB. From this I assume it IS an issue with Ex Nihilo Sequentia sieves and fake players; I would have never thought of that. Thanks for your help, I'll close this issue.

Daxturus commented 1 month ago

Thanks again. (I forgot to hit close lol)