0

Assume I'm working on a multiplayer online game. Each group of players may start an instance of the game to play. Take League Of Legends as an example.

At any moment of time, there are many game matches being served at the same time. My question is about the architecture of this case. Here are my suggestions:

Assume we have a cloud with a gateway. Any game instance requires a game server behind this gateway to serve the game. For different clients outside the cloud to access different game servers in the cloud, the gateway may differentiate between connections according to ports. It is like we have one machine with many processes each of them listening on a different port.

Is this the best we can get?

Is there another way for the gateway to differentiate connections and forward them to different game instances?

Notice that these are socket connections NOT HTTP requests to an API gateway.

EDIT 1: This question is not about Load Balancing

The keyword is ports. Will each match be served on a different port? or is there another way to serve multiple services on the same host (host = IP)?

Elaboration: I'm using client-server model for each match instance. So multiple clients may connect to the same match server to participate in the same match. Each match need to be server by a match server.

The limitation in mind is: For one host (=IP) to serve multiple services it need to provide them on different ports. Match 1 on port 1234. So clients participating in match 1 will connect to and communicate with the match server on port 1234.

EDIT 2: Scalability is the target

My match server does not calculate and maintain the world of many matches. It maintains the world of one match. This is why each match need another instance of the match server. It is not scalable to have all clients communicating about different matches to connect to one process and to be processed by one process.

My idea is to serve the world of each match by different process. This will require each process to be listening on a different port.

Example: Any client will start a TCP connection with a server listening on port A. Is there is a way to serve multiple MatchServers on the same port A (so that more simultaneous MatchServers won't result in more ports)?

Is there a better scalable way to serve the different worlds of multiple matches?

Meena Alfons
  • 1,230
  • 2
  • 13
  • 30

1 Answers1

0

Short answer: you probably shouldn't use proxy-gateway to handle user connections unless you are absolutely sure there's no other way - you are severely limiting your scaling ability.

Long answer:

What you've described is just a load balancing problem. You can find plenty of solutions based on given restrictions via google.

For League Of Legends it can be quite simple: using some health-check find server with lowest amount of load and stick (kinda like sticky sessions) current game to this server - until the game is finished any computations for particular game are made there. You could use any kind of caching mechanism to store game - server relation for subsequent requests on gateway side.

Another, a bit more complicated example could be data storage for statistics for particular game - it's usually solved via sharding which is a usual consequence of distributed computing. It could be solved this way: use some kind of hashing function (for example, modulo) with game ID as parameter to calculate server number. For example 18283 mod 15 = 13 for game ID = 18283 and 15 available shards - so 13th server should store/serve this data.

Main problem here would be "rebalancing" - adding/remove a shard from cluster, for example.

Those are just two examples, you can google more of them using appropriate keywords. Just keep in mind that all of this is just a subset of problems of distributed computing.

Wintermute
  • 1,501
  • 17
  • 22
  • My question is not about load balancing. The keyword in my question was **ports**. Will each match be served on a different port? or is there another way to serve multiple services on the same host (host = IP)? – Meena Alfons Jul 02 '18 at 18:56
  • There is no need to serve every match on different port, you can use same port for every client, each of them will use its own socket – Wintermute Jul 03 '18 at 06:50
  • My match server does not calculate and maintain the world of many matches. It maintains the world of one match. This is why each match need another instance of the match server. It is not scalable to have all clients communicating about different matches to connect to one process and to be processed by one process. – Meena Alfons Jul 03 '18 at 12:25
  • Still, I don't understand why do you need different port for each match/world/whatever? Can you provide a simple illustration of your data flow? – Wintermute Jul 03 '18 at 13:20
  • The MatchServer simulates one game. All participating clients connect to the server. The server multicasts the state of the game and receives actions/inputs from clients. – Meena Alfons Jul 03 '18 at 21:29
  • Okay, and what do you want to scale? Amount of MatchServers or amount of clients per MatchServer? – Wintermute Jul 04 '18 at 12:51
  • Amount of match servers which equals the mount of concurrent matches. I assure you that I know that theoretically infinite number of clients can connect to one MatchServer listening on one port. I need to serve many matches (many MatchServers) simultaneously. Any ideas? – Meena Alfons Jul 04 '18 at 17:05
  • I'm in no way implying that you don't know about number of clients per port, I'm sorry if it appeared this way. Back to your question, what do you about about serving MatchServer's socket via single gateway? Here's crude scheme: https://pasteboard.co/Ht2aKft.png This way your gateway won't be under any serious load and actual game data will flow directly between client and Matchserver – Wintermute Jul 05 '18 at 10:25
  • Thanks for your efforts. I don't understand GetServer & GetSocket calls in that image. The question is simply: Is there is a way to serve multiple MatchServers on the same port A (so that more simultaneous MatchServers won't result in more ports)? Or is there a better way? – Meena Alfons Jul 05 '18 at 23:27
  • 1
    Is it possible to discern one MatchServer from another by any other parameter except port? Some packet value, maybe? If the answer is yes, then - yes, you can use same port to serve multiple MatchServers using 1 external port. Your MatchServers will use up local sockets while your gateway will bind external port and forward connection to appropriate socket – Wintermute Jul 06 '18 at 08:06
  • That solutions as you presented it seems obvious. Use key information in the packet to route it to one of internal sockets.I see the potential of this solution. The abstract problem is to serve multiple changing (increasing) services in a scalable way (not necessarily ports). Do think this is the best we can do (using one external socket and map packets to multiple internal sockets)? – Meena Alfons Jul 06 '18 at 08:15
  • 1
    Yep, that's the first step. Next one would be scaling MatchServers to a cluster (probably, N MatchServers to 1 physical machine) with same port-socket scheme per machine and global load balancing gateway which will serve appropriate MatchServer machine to a client (or just pass-thru proxy it), kinda like I've described in the scheme above – Wintermute Jul 06 '18 at 09:29