If you really don't want the overhead of I / O, just save the state of the game in the global object with the game key:
var global_gamesate = {}
Then, on each connection, verify that the game identifier should restore the state of the game:
var gamestate = global_gamestate[game_id];
Presumably, you already have a mechanism for matching client sessions with a game identifier.
Usually the state of the game is small and is unlikely to take up much RAM. Let me be pessimistic and assume that each state of the game takes 500K. Then you can serve two thousand <thousand games <thousand thousand (four <thousand> thousand users, if we accept two users per game) for each gigabyte of RAM on your server.
However, I would like to note that databases such as MySQL already implement caching (which is configurable), so loading the most frequently used data is mostly loaded from RAM with a bit of socket I / O overhead. The advantages of databases are that you can have much more data than you have RAM, because they store the rest on disk.
If your program ever reaches the load, when you start thinking of writing your own disk serialization algorithm to implement the swap file, you basically reinvent the wheel. In this case, I would say that you are using databases.
slebetman
source share