Poni
Poni

Reputation: 11327

online lobby system - games list

Been reading a bit about the subject, and out of curiosity, online games which maintain a "lobby" system that lists games;
How do they keep each client synchronized with the current games list state?

I'm talking in a "client asks for the games list update" terms and not in event driven terms (game's state changes and immediately broadcasts it <--- not scalable!).

Possible scenraio:
A server holds 5000 connections to online players.
It has a list of 1000 games.
A client asks for a games list update every one second.
Now the server needs to iterate through all the games list and compare the last update time of each particular game, then if it sees that the player's last update is older it will send an update.
This means that every one second it is going to have (5000 * 1000 = 5,000,000) iterations!

Is there any practical way to avoid it?
Did you do it already, and can share a tip with me?

I've been thinking about having a cache. What's your solution?

Upvotes: 1

Views: 790

Answers (2)

meriton
meriton

Reputation: 70584

First off, 5 million comparisons a second will not noticeably tax modern hardware. Let's assume a comparison takes 10 cycles on a 1 GHz Cpu. Then this would cause a CPU load of merly 5%. Of course one could easily optimize that, but we have more important things to do, don't we?

A much more likely bottleneck is network bandwidth. Do I really need to transfer data about 1000 games to each client every second? Let's assume 100 bytes data per game. This would equate to a bandwith of about 1MBit for each player.

Fortunately, the clients need not know about every game. A typical pattern would be that the user states which games he wants (for instance by game type), the client sends this filter to the server, and the server sends only the matching games.

Upvotes: 2

Jack
Jack

Reputation: 133609

You could invert the order: whenever your gamelist change you send all your clients an update.

If you want to save bandwidth you should create a small update packet, that contains just informations that differs from last update sent, with an int id for your games this will be easy.

Keep all the clients synched to the same lobby status, also because this is what you need to do.. why do you want to care about different timings when you are publishing a common list?

Upvotes: 1

Related Questions