I am currently developing a game for education purposes.
The game is a small chat where each player has a figure. This figure has its position written in a MySQL database, and updates every time a players moves his figure.
Currently, every 60 frames, the game updates all the players positions and changes them in the gameclient. The performance of the database is not my only concern, as this causes the game framerate to drop to around 30-50 fps.
Obviously, this generates 1 query for position updates a second (Game runs at 60fps), per player. Thinking a little larger than me and a few friends as users, i could imagine this may be a problem.
Would a standard rented webserver be able to handle this? How could i improve it? (It can’t update the positions less than once a second)
I hope you have some ideas 🙂
This sort of data is not really saved to a database after every single change, instead it’s kept in some kind of in-memory context so that it’s much faster to access. What you store in a database is things that change less frequently, like on the order of once per minute.
What you might do is snapshot the current in-memory context to the database on a regular schedule. That is to say every minute or so you would “persist” the game state so that if the engine crashed it could restore from that point. If you create the proper architecture, this would be no more difficult than calling a method periodically.
Certain things may be persisted immediately to avoid people exploiting this lag between an action occurring and the record of that action being permanent. For example, any transactions with in-game currency would be recorded immediately and the in-memory cache would not be trusted for these.
For low numbers of players, like under a hundred, you should have no problem with using a commodity VPS. To host more players you would have to be very careful to be efficient.