eldoriarpg / SchematicBrushReborn

A minecraft plugin which allows you to use schematics in a brush via world edit
GNU Affero General Public License v3.0
20 stars 12 forks source link

High CPU usage #12

Closed SamB440 closed 3 years ago

SamB440 commented 3 years ago

Hi,

This plugin causes high CPU usage when installed (an entire core!).

Without SBR: image With SBR: image

This is CPU usage off the main server thread: image And thus I believe the likely cause is this class here? https://github.com/eldoriarpg/SchematicBrushReborn/blob/master/src/main/java/de/eldoria/schematicbrush/schematics/SchematicCache.java

Server version:

This server is running Tuinity version git-Tuinity-"7d36676" (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT)
You are 9 version(s) behind
Previous version: git-Treaty-"c4380f2" (MC: 1.16.5) (Treaty is our custom server implementation)

Plugin version: 1.4.2a

Thanks!

SirYwell commented 3 years ago

Could you provide a spark profiling (for all threads)? That would be helpful to track down the issue.

rainbowdashlabs commented 3 years ago

That's an interesting observation.

I reworked this process recently in order to reduce the GC overhead. The currently present implementation of the SchematicCache can be found here: https://github.com/eldoriarpg/SchematicBrushReborn/blob/development/src/main/java/de/eldoria/schematicbrush/schematics/SchematicCache.java

I use a WatchService, which uses a notification based system in an own Thread. This may be the thread which is using one core probably. However this thread is waiting most of the time and not doing anything, so I am a bit curious what the cause here is.

I also observed the core usage on my windows machine and I can only identity 4 cores which show a behavior like you described, or at least a bit. However this is not a full used core and I dont know on which cores the threads of paper are running for other stuff.

I looked a bit around and found some sources, which note the existence of something called inotify-tools which provides io notification events for the java application which resolved those high cpu issues. So it is maybe not directly related to the plugin but the OS itself. Maybe you can try it out and tell me if those tools are installed and if not if installing them resolves the issue. https://stackoverflow.com/questions/24739280/watchservice-uses-100-of-cpu-on-centos

SamB440 commented 3 years ago

Could you provide a spark profiling (for all threads)? That would be helpful to track down the issue.

https://spark.lucko.me/8648EKkLBQ

I looked a bit around and found some sources, which note the existence of something called inotify-tools which provides io notification events for the java application which resolved those high cpu issues. So it is maybe not directly related to the plugin but the OS itself. Maybe you can try it out and tell me if those tools are installed and if not if installing them resolves the issue. https://stackoverflow.com/questions/24739280/watchservice-uses-100-of-cpu-on-centos

I will look into this in a few days time

rainbowdashlabs commented 3 years ago

Any news here? I am quite curious about this :D

SamB440 commented 3 years ago

We have since installed the inotify-tools, but haven't had the chance to install the plugin back again. We are currently updating to 1.17 as well.

rainbowdashlabs commented 3 years ago

Alright. I just released the 1.17 ready version of Schematic Brush. Please keep me updated on this ^^ Would be good to know when this issue arises again in the future.

SamB440 commented 3 years ago

Ok, I've installed this on one of my personal servers (which means this can also be reproduced elsewhere).

Using v1.4.3 and Tuinity 1.16.5 on Ubuntu 20.04.2, with a JDK 16 image with inotify-tools. Running using pterodactyl panel.

openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-16.0.1+9 (build 16.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-16.0.1+9 (build 16.0.1+9, mixed mode, sharing)

With plugin, entire core almost always active: image

Spark with plugin installed (--thread *, 60s): https://spark.lucko.me/3vh7Jl7HJV

We can see it in htop (103% cpu): image

Without plugin, normal CPU usage: image

Spark without plugin installed (--thread *, 60s): https://spark.lucko.me/Ld3Cax0wj2

rainbowdashlabs commented 3 years ago

Thanks for reaching me out again.

I have two good news. First I switched to linux for development and I can reproduce this on my linux system now. Second I found the issue and fixed it. The core utilization is now down to a few percent, where the most should not be related to the running minecraft server. image I deployed the change in a snapshot. You can download it here. https://eldonexus.de/repository/maven-public/de/eldoria/schematicbrushreborn/1.4.4-SNAPSHOT/schematicbrushreborn-1.4.4-20210713.120217-1-all.jar

SamB440 commented 3 years ago

I can confirm that the new version fixes it

rainbowdashlabs commented 3 years ago

Glad that the issue is resolved now ^^ Thanks for contacting me ^^