Grasscutters / Grasscutter

A server software reimplementation for a certain anime game.
https://grasscutter.io/
GNU Affero General Public License v3.0
16.21k stars 4.47k forks source link

[Bug] Use "give all" to occupy 100% of the CPU #2353

Open SuppoMeme opened 1 year ago

SuppoMeme commented 1 year ago

When using instructions such as "give all" or even "give weapons" to add a large number of items, the CPU usage increases sharply, but this did not occur when testing with grasscutter-1.5.1. Using the same "give all" command, gc1.7.1 requires about 10 times the cpu of gc1.5.1 (it may take up more if my cpu performance is better.), and gc1.5.1 usually takes up less than 30 seconds. After the execution is completed, the CPU usage returns to normal levels, while gc1.7.1 takes about 5 minutes. I don't know if this is a bug but I still want to give feedback.

KingRainbow44 commented 1 year ago

this is mostly due to how items are given (they are given one by one, each item being an individual database operation) ill go ahead and add a fix for this in the hyper-optimization branch of gc

SuppoMeme commented 1 year ago

OK, thank you. I removed the thread mechanism in DatabaseHelper and wrote data directly to the database like gc1.5.1, which temporarily alleviated this problem. In theory, it can improve the problem of players disconnecting from the game due to excessive CPU usage.

KingRainbow44 commented 1 year ago

...have you tried using hyper-optimization? it uses the same thread pool concept but to a better degree

SuppoMeme commented 1 year ago

I tried, but the compiled program cannot enter the game. The screen is white. The database is cleared, and there are no errors on the console, only many "Client connected from /192.168.1.123".

KingRainbow44 commented 1 year ago

just fixed the branch, can you try it again?