1

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 :-)

3
  • 1
    Keep the positions in memory, not in the database. Commented Dec 2, 2012 at 11:08
  • Depends on infrastructure, but you could keep the cache in memory (ie don't read from the database) and only write once in a while to the database. I assume it's no disaster if you lose the last few seconds if the server goes down? Commented Dec 2, 2012 at 11:09
  • How would i keep them in the memory? The positions are updating all the time when people are moving around, so i need to show the actual positions on all the other clients as well Commented Dec 2, 2012 at 11:22

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use an in-memory Java database, which allows you to update the players more frequently. Changes are then stored in the MySQL database at a less frequent rate.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.