delvr / Farseek

A Scala API for Minecraft mods.
https://minecraft.curseforge.com/projects/farseek
20 stars 4 forks source link

Possible performance issues when using pregen tools. #33

Closed RebirthGaming closed 6 years ago

RebirthGaming commented 6 years ago

Currently using Farseek 2.0.1 and Streams 0.3.3, MC 1.7.10

Modpack is "Tradewinds" (A custom pack I created, don't have full modlist on hand, but can provide if needed)

The summary of the issue I am having is that when I execute processes to pregenerate chunks (such as using World Border's /wb fill command, or using ChunkPregenerator mod to do the same - that is, these tools will generate chunks out to a defined radius), or, when a player such as myself explores the world to generate chunks too rapidly, the server will timeout. This also appears to occur in singleplayer.

The resulting error is a hard freeze - a timed out state - where all connected players receive a timed out error, and commands can not be sent through console. Logging also ceases, meaning that I do not have any logs that help identify the cause. This requires me to manually reboot the server (killing the process, since console commands do not work when timed out)

This is a very significant issue in my particular case, due to how I've designed and setup my modpack/server. Pregenning is a must for my modpack, so I'm quite invested in seeing this fixed.

Now, I'm not 100% sure if it's indeed Farseek causing the problem. What I did was install WarmRoast onto my server (it's a VM profiling tool), ran the chunk gen command via World Border, waited until the timeout occurred, then ran the profiler.

It pointed to two possible causes (I think - I could be reading the profiler wrong), one being Farseek and the other RTG (these two had the highest thread consumption and latency (ms) times)

It may even be both, considering that Farseek/Streams was somewhat recently updated to have increased compatibility with RTG (which I believe is what fixed the previous issue of cobblestone streams), but I'm not sure.

Either way, here's a screencap of the WarmRoast logs: http://imgur.com/a/lmGci

World gen mods I'm using are RTG, CC, Streams, SGUBetterGeo, COFH, ExtraBiomesXL, and Highlands. There's also decoration mods such as Recurrent Complex, Plant Mega Pack, and Pam's Harvestcraft.

delvr commented 6 years ago

Hi RebirthGaming, thanks for reporting this. Streams does have a hard time with pregen as some others have reported. I've never used any pregen tool myself so the more details you can give me on how you use it on your server, the better I can repro the issue. Thanks!

RebirthGaming commented 6 years ago

I'm not entirely sure how familiar you are with servers and plugins/server tools, so I'll try to be as thorough as possible.

Pregen tools can be either plugins or mods (that is, either a bukkit plugin such as World Border, or a pure Forge mod such as ChunkPregenerator)

Simply put, it's a tool that server admins/OPs can utilize to generate chunks out to a defined radius. For example, I can run a command with World Border that sets a border with a radius of 1000 chunks from my current location/defined XYZ coords. Then I can follow up with a command such as "/wb world fill [frequency]" which will generate all chunks out to the world border at the frequency (chunks per second) I defined.

The whole purpose behind these pregen tools are to generate chunks. The reason why server admins might want to do this is because players exploring a world where chunks have not yet been generated can cause a server to slow down as it dedicates resources to generating new chunks. If an OP such as myself generates these chunks beforehand, though, then the server will unload the generated chunks (so they don't use server resources), and then when a player enters those unloaded chunks, the server simply has to load them. It's not generating the chunk as if it was brand new, because that was already done with the pregen tool.

Pregen tools are basically the equivalent of players flying around at max speed, causing the server to generate all new chunks that player enters. The difference is that pregen tools are usually 'smarter' about it and use as little resources as possible to do this, and can run while players are offline.

The result, ideally, is that a server would have the entire world generated and saved to the world folder, and no chunks ever have to be generated anew - only loaded when players enter a chunk - and significantly reduces a server's resource demand. Of course, running the pregen tools will consume a lot of a server's resources at the time it's being ran, but the idea is to do it before players are on the server, so they don't have to experience the lag that comes with generating new chunks.

The specific issue I'm having is that it seems like when certain chunks are generated, it causes the VM to stall and become unresponsive. While a pregen tool could cause the server to slow down, I haven't ever experienced it causing (other) servers to become completely unresponsive like it does in this particular case. It should at the very least keep running. I've set WB to run at its lowest frequency (1 chunk per second) and it will still often cause the VM/server to time out almost immediately (which makes me suspect that it's not an issue of available RAM/CPU, but rather something is asking for WAY more resources than needed - IE a memory leak). I even tried a different pregen tool (ChunkPregenerator), which the developer created in a way where it dynamically changes the frequency of chunk loading based on available server resources, and the result is the same.

Between using pregen tools, and even flying around manually on my server to generate chunks (which results in time outs), I suspect that something is just giving the server a hard time with keeping up - that when certain chunks or maybe too many chunks at once are being generated, it completely exhausts the server's resources and freezes the JVM.

Again, it's hard for me to determine exactly what the cause is (logs don't provide any meaningful info related to this), and only reporting this here because my VM profiler suggests it's either Farseek or RTG.

I haven't yet reported this to RTG. I reported it here first because it sounds quite similar to another issue in your issue tracker, but if you think I should bring this to RTG as well, I can do so.

delvr commented 6 years ago

Thanks for these details. How many chunks did you try to pre-gen? I just tried using Chunk Pregenerator with command "/pregen startradius 0 0 500" on a new RTG new world with Streams loaded. So far reported RAM usage was around 500 MB after about 100,000 chunks, and about 1 GB after 200,000. So there is an increase, but no JVM freezes yet. How did your test differ?

Next I can try WorldBorder (need to figure out Bukkit first, never used it) but I don't see a version for 1.7.10 in https://dev.bukkit.org/projects/worldborder/files. Where did you get yours?

RebirthGaming commented 6 years ago

I've tried all sorts of ranges. I've had more success pregenning smaller batches at a time, like 100 chunks, but I can't tell if it's because it's not 'hitting' problem chunks, or what.

Regarding bukkit, you'll want to use the latest craftbukkit version prior to 1.8+ (looking at that link, it looks like v1.8.1 for CB 1.7.9 is the latest 1.7.10 compatible version) I'm not sure how familiar you are with servers and using bukkit alongside forge, but just to point this out, you'll need Cauldron, which is a server.jar that combines bukkit with forge, allowing mods and plugins to run simultaneously on a server.

Although, none of that may be necessary. I did some more investigating, and it may not be RTG nor Farseek. I did run the profiler once more after rebooting the server and executing a /wb fill command (which froze the VM immediately), and it suggested RTG was more of a problem than farseek... so it seems inconsistent at best which makes me doubt it's either mod actually causing the problem, and instead something else is causing the issue, but it's just RTG/Farseek being 'the last' to report anything to the VM. (That, or, it's an issue that hooks into biomes, which just causes these two to show up in the profiler because they are the 'biomes')

Here's a screencap of my latest vm profile: imgur.com/bFVWA7d

Out of curiosity, though, I backed up my world, removed RTG, CC, Streams and Farseek, and created a new world using the world type "Highlands" (needed to set something here other than RTG), then created a new world.

Interestingly, the VM froze immediately upon the world being loaded. So, I profiled it and discovered this:

imgur.com/5ztswLk

Which kind of confirms what I thought - it's not RTG nor Farseek, and instead the underlying cause is just causing whatever biome mod is being used to show up in WarmRoast. Furthermore, those EnchantBook classes are new, so I'm thinking something with an enchantment is generating in a chest which causes that chunk to just choke up and freeze the VM.

RebirthGaming commented 6 years ago

Fixed. Turns out it was Artifacts.

Apparently Artifacts dungeons were enabled and were having a severe issue loading into the world upon new chunk gen, thus causing the timeout. Idiot me never disabled them in the config. It's certainly an issue on its own but does not impact my particular situation since I don't want the Artifact structures to generate at all in my pack.

We disabled Artifacts world gen in the config and all is well.

Anywho, thanks for investigating, and apologies for the false negative!

delvr commented 6 years ago

Awesome, thanks for investigating and letting me know!