canary icon indicating copy to clipboard operation
canary copied to clipboard

[Most of the saves put a huge toll on the game's database]

Open ThiagoNBCoding opened this issue 2 years ago • 1 comments

Priority

Critical

Area

  • [X] Datapack
  • [X] Source
  • [ ] Map
  • [ ] Other

What happened?

Given a somewhat considerable playerbase(let's say 600+ players), the saving actions start taking QUITE A TOLL at the database, to the point the game becomes basically unplayable.

My suggestion would be to reduce the amount of saves, to not only more critical situations, and also to make it so save(not talking about server save, talking about saving characters, their depots, etc) occurs by 'steps' and not all at once.

Saving every time somebody levels up a skill, for example, makes the game unplayable if there's like 300 players training on a dummy. There's dozens of other stances of this, not only related to training, but also making offers on market, buying/selling items in general, etc.

What OS are you seeing the problem on?

Linux

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

ThiagoNBCoding avatar Sep 18 '22 20:09 ThiagoNBCoding

What do you mean by saving actions?

The IOLoginData::savePlayer function that saves the player in the database is only called in a handful of places, but there's none when somebody levels up or gains a skill. The player itself is only saved when:

  • if someone buys/sells items on the market (if the player is offline)
  • when a mail is sent (if the player is offline)
  • during server saves
  • when paying rent to a house
  • when losing a house
  • when it dies/logout

I believe your meaning about training on a dummy is just an example, but I couldn't find where it would be saved after each skill gain.

On the other hand, I do agree that there are multiple places where the database is used inefficiently. Still, some of them are necessary, like market offers, deaths, and logouts where we need to ensure the state of the game after said action; being in the OpenTibia community, it is common to suffer from DDoS attacks, errors in the code, and other issues that can cause rollbacks, this is why most of these save actions are done in the way they are done.

I believe the most optimal way to understand your problem and use your server as a case to improve the code is to understand what is causing the lag, do you have database logs/metrics to understand exactly where the issue is?

Did you optimize your database settings or you're running with the defaults?

If you want, we can chat on discord to analyze the DB load. Just send me a message bsmk#7571

bosmak avatar Sep 19 '22 17:09 bosmak

Unfortunately, we have not received a response from the author and will be closing this issue. We would like to remind everyone that the save server by interval feature should be used with caution, especially on servers with many players. This is a temporary solution that may not be sustainable in the long term.

For example, Tibia, a commercial game with a dedicated team, saves the game only once a day to ensure stability. In contrast, open source projects rely on community support and may not have the same resources. If you are running a server with a high player count, it is important to ensure that it can handle the demands of the players without relying on interval saving. We recommend exploring other options to ensure server stability.

dudantas avatar Feb 28 '23 05:02 dudantas