4
\$\begingroup\$

The game I'm working on currently has a Client in Flash AS3, and a Server in C# (multithreaded).

Currently I use mySQL to handle logins (Raw access: no middleman for accessing the database) which seems to be extremely quick.

My question is would using a mySQL database be quick enough for a fairly simple real time game?

My game functions in a similar way to Diablo2, League of Legends, or even Starcraft:


  1. User logs in
  2. User is taken to lobby
  3. From lobby user may view active games
  4. User's group into 2-8 for games which exist on the server in it's own thread

Now, the game has been designed in such a way to minimize server calculations, while still providing zero trust to clients. Is it possible to use SQL in a way to store and manipulate all game data, for each game? ie:


  1. Users 1 through 8 all create 50 units
  2. Each user commands all of their units to move to a location on the map
  3. Units attack each other
  4. etc.

Is SQL fast enough to handle this kind of data traffic? Or would it be better to store it all in memory? Or is there some alternative (such as paging) I haven't considered?

\$\endgroup\$

3 Answers 3

6
\$\begingroup\$

What do you mean by "Raw access"? If it means what I think it means you have got a gaping security hole.

As for the performance question, it would be stupid to try using a database for such a job, for a ballpark figure I'd say an average database is 1000 times slower than memory. Just keep everything in application memory, I don't think you'll run out of memory before you hit some other bottleneck.

\$\endgroup\$
1
  • \$\begingroup\$ There are some third party solutions to connect C#/.Net to an SQL database that provide some extra features but slow things down considerably. Raw meaning I avoid those, and simply initiate a connection and run commands. \$\endgroup\$ Commented Aug 17, 2011 at 22:39
5
\$\begingroup\$

Typically, simulation state is kept in memory and the server will send it out to the clients while longer term info like active games and who is connected would be kept in a database that all the services like the lobby can pull info from.

Raw access, direct from the client with SQL commands? Bad idea. Have the server receive requests, which you then internally create the SQL commands from.

\$\endgroup\$
4
  • \$\begingroup\$ Raw access by the server to a local SQL database, all data is completely validated before any access is made. Clients have no direct or indirect access to the database. \$\endgroup\$ Commented Aug 17, 2011 at 22:37
  • 1
    \$\begingroup\$ Oh good, that works well. Have you researched networked RTS/multiplayer games at all? Even full scale MMOs keep the world simulations in memory and use the database for persistent and transactional purposes only. If you're creating something like those titles you need client updates of maybe 10 or 20 times a second and that's pushed from the server, not polled from the client. \$\endgroup\$ Commented Aug 18, 2011 at 0:30
  • \$\begingroup\$ I have done some research, but was more curious if this sort of system was possible. Looks like I've got a lot more reading to do! \$\endgroup\$ Commented Aug 18, 2011 at 9:47
  • \$\begingroup\$ Could you be more detailed on "in-memory" since "in-memory" offers a large space of different operations. \$\endgroup\$ Commented Aug 18, 2011 at 15:03
3
\$\begingroup\$

I'd have to say it really depends on your game/simulation and how well you can model it in SQL.

Nowadays SQL Servers can keep lots of data 'live' in memory, and optimize access and processing of the data extremely well.

And SQL should scale, in many ways, number of users, servers, processors, memory etc. - Some of this really difficult stuff to do from scratch....

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .