DailyStruggle / RTP

fun with spatial math
25 stars 6 forks source link

Suggestion about performing a blocking I/O operation on the main thread #6

Closed FunkyNico closed 2 years ago

FunkyNico commented 2 years ago

Hello, I have found this suggestion from another spigot plugin called Lagmonitor : Make stop the plugin from doing a blocking I/O operation on the main thread because this could affect the server performance, the thread pauses until it gets the response. Such operations should be performed asynchronous from the main thread. Besides gameplay performance it could also improve startup time.

In this case looks like this happen when the server is closing up.

RTP Version: 1.3.23 / Server: Purpur-1762 (MC: 1.19.2) (Implementing API version 1.19.2-R0.1-SNAPSHOT) (Git: 39e30d6 on HEAD).

Log: https://logs.apexminecrafthosting.com/oT6sqAH

Thanks =D

DailyStruggle commented 2 years ago

this happens because every file i/o will block the main thread.

doing so asynchronously is ill-advised on shutdown, and spigot added nag messages to point out when an async task is still running after a plugin is disabled.

the main thread is supposed to pause for plugin disable on shutdown.

this log does not reference anything that impacts startup times, unless you're specifically worried about restart times.

https://github.com/DailyStruggle/RTP/blob/6d43291dc14d9872861fb90f92cf64a88dd51f29/src/main/java/leafcraft/rtp/tools/Cache.java#L55

On startup, the plugin loads it largest files asynchronously.

DailyStruggle commented 2 years ago

This is more of a problem with LagMonitor not stopping this check on shutdown, as blocking for file or database I/O during onDisable is advised and expected.