Bastian / bstats-metrics

The different bStats Metrics classes
https://bStats.org
MIT License
99 stars 114 forks source link

Submit data asynchronously on bukkit/spigot rather than on server thread #115

Closed BenCodez closed 1 year ago

BenCodez commented 1 year ago

Don't submit data on server thread, can create lag spikes.

Not sure if it is necessary to run on server thread for spigot servers, so not sure what the side effects are.

Bastian commented 1 year ago

Sending data to bStats is async. Collecting the data before sending it (i.e. for custom charts) is sync. The reason is, that Bukkit's APIs are usually not thread-safe.

I see that this might be a problem/inconvenience for custom charts that need data from a database or another slow data source.

Making everything async is probably not the best idea since there's still the issue of Bukkit APIs not being thread-safe. At least, it should be possible to toggle the behavior.

BenCodez commented 1 year ago

Maybe one solution is to allow a simple toggle or even allow each metrics chart can decide if it runs async or sync?

Either way I'll close this since this probably won't be best solution for best of both worlds.

Bobcat00 commented 1 year ago

I see that this might be a problem/inconvenience for custom charts that need data from a database or another slow data source.

It seems to me it's incumbent on the plugin to handle this. For example, by running a periodic task that retrieves the data and saves it in local variables which can be accessed from the main thread.