MLG-Fortress / PopulationDensity

The now-official repository of the PopulationDensity Bukkit plugin
https://dev.bukkit.org/projects/population-density
10 stars 10 forks source link

Option to simply open a region at random #26

Closed FrankHeijden closed 6 years ago

FrankHeijden commented 7 years ago

Heya,

Ive noticed the region "scanner" takes a lot of resources when its being called, i'd like a feature which just selects a random regionpost which does not scan the area but just randomly selects one through the world (and respecting plugins such as WorldBorder + vanilla border).

I hope this is possible :)

Frank

RoboMWM commented 7 years ago

Alright, I think I know what you're requesting:

Instead of checking to ensure there's enough resources to spawn new players at a given region post, just select one at random inside of the world border.

So there's several issues with this:

The "scanner" uses scheduled tasks so it's only scanning a section of the area per tick (or per x amount of ticks, haven't look that deeply into it). So it should provide the server with more than enough time to catch up, if it ever did cause lag that is. I could add checks to "skip" or postpone checking if there are x amount of players online/tps is dropping I suppose... but I'm sure you're just seeing the scary red numbers/orange graph in the timings?

FrankHeijden commented 7 years ago

and changing the scanner from such intensive to asynchronous with FAWE?

RoboMWM commented 7 years ago

asynchronous with FAWE?

An aside: FAWE, as any new async plugin that modifies/deals with the world, was once not performing thread-safe actions. Though Empire92 has eventually resolved those issues (afaik, I haven't been following lately) still some are weary of it.

As a general rule, the vast majority of Bukkit is not thread-safe for async operations. Even if operations were performed "async" a lot of thread locking would have to occur, thus resulting in minimal to no gain to performing an operation async.

FAWE mostly benefits from directly accessing Minecraft's code (NMS). Downside to this is that it needs to be updated with every MC release.

I'll take a look at the code if you can produce some timings, but I think the bigger issue here isn't so much the scanning than it is the potential chunk generation caused by loading new chunks.

FrankHeijden commented 7 years ago

Cool, ill provide some Timings when my server reboots, because thats the moment when the scanning is being called.

Thank you for your time 🥇

RoboMWM commented 7 years ago

because thats the moment when the scanning is being called.

Your server is also doing a lot of other things at startup (depending on plugins), so might not exactly be fair to do it then. That being said, I probably will disable the check on startup.

RoboMWM commented 6 years ago

So iirc, the scanner does indeed work asynchronously. It retrieves a ChunkSnapshot and iterates over the materials in an async task. So what you might be seeing is your overall CPU usage going up - but this shouldn't be affecting Minecraft's (or any other) thread since it's not operating in that thread (apart from perhaps loading the chunks in the region).

RoboMWM commented 6 years ago

Provided that no info of said resource usage was provided, as well as the confirmation that the scanner does indeed work asynchronously, I'll close this issue. The only thing I could imagine one would want is an option for the scanner to not scan on startup, which I'm okay with adding.