2

I am developing a multiplayer game (client-server model) and I am stuck when it comes to scaling its servers.

I understand that most games never even reach 10 000+ players, and I don't think mine will either. Though if I would be very lucky to get that I want to develop the servers so they cannot become a huge obsticle later.

I have searched a lot for a solution to my problem on the internet, checking GDC talks about it and checking other posts on this website, but none of them seems to solve my specific problem.

My current setup is below and all servers are written in C++ using ENet as my network library.

Game server

This server handles the actual gameplay of the game and requires quite a lot of CPU and packages being sent between the server and its connected clients. But this dedicated server is hosted by the players themselves, so I don't have to think about scaling it at all.

Lobby server

This server handles the server list, containing all servers currently up.

  • All game servers are sending a UDP package to this server every 5 seconds to say they are still alive. This is so the lobby server can keep an updated list of all servers currently online.

  • All clients are sending a UDP package to this server when they want to fetch all servers (which is only in the server list screen), and the lobby server sends back a list of all servers. This does not happen that often and the lobby server is limited to send 4 servers per second to a client (and not a huge package containing all servers).

Login server

This server handles creating accounts, lost password, logins, friends and their current game status, private messages to other logged in players and player profiles that specifies what in-game items they have.

  • All clients are sending a UDP package to this server every 5 seconds to say they are still alive, while also sending what game they are currently in. The server then sends back their friend lists online/offline/in-game statuses. This is so their friends can keep an updated list of which friend is online/offline/in-game.

  • It sends messages only with player actions otherwise, like creating an account, logging in, changing/resetting password, adding/removing/ignoring a friend, private messages to friends, etc.

My questions

What I am worried about is that my lobby and login server might not be scalable and that they would have too much traffic on them.

1. Could they in theory be hosted on just a single computer? Or would it be too much traffic for 10 000+ players?

2. If they can be hosted on a single computer, will the servers still not have issues for people that live far away?
Would it be better to have the lobby and login servers per region of the world in that case? The bad thing about that is that the players would not be able to see servers in the US if they live in Europe, and that their account and items would not exist on the other servers.

3. Might be far-fetched, but if I would rewrite both servers to instead be on a website with a database and make the client/game server do web requests instead (such as HTTPS or calling a php with specific headers), would it help in solving my problems somehow?

MrPersson
  • 23
  • 3
  • 1
    Not sure what kind of answer you're expecting here except: It depends. On a lot of factors, and a SO post is not the place to go through them all. If it's not a problem yet, don't worry about it. Or run some stress-tests on your servers to see how much load they can handle. – super Dec 22 '20 at 18:15
  • Welcome to SO. Great questions, good work! But this is far beyond the scope where you can get help here. This is a site for software developers which need to get help for a specific, reproducible problem. – marsh-wiggle Dec 22 '20 at 18:15
  • I agree it will be hard to get an answer here. It comes down to limiting the amount of unnecessary traffic, and also writing very efficient UDP code (which typically means asynchronous, based on IOCP if we are talking Windows). Also avoid allocating any memory in UDP routines, use static buffers/memory pooling instead. – Sven Nilsson Dec 22 '20 at 19:25

2 Answers2

0

All your problems and questions are solved by serverless cloud based solution AWS Lambda e.g. or similar. In this case the scalability is not your problem. Just develop the logic. This will save you much time.

If you would like to make servers as single app hosted by your own server. Consider using something like e.g. Go instead of C++. It's designed exactly for these purposes. I mean highly loaded web/network services.

4xy
  • 3,494
  • 2
  • 20
  • 35
  • Thank you for your reply! I have checked AWS before as well, but I never understand how it actually solves my problem. For each login and lobby server, it has its own data per machine, that means all accounts and all games in the game list are per server started. If I added many more, that would mean I would have to create a database located somewhere that all servers use, which would again make the servers slow because if the database is in the US while a player is from (for example) China, it will be very slow. I understand that service works much better for something like game servers. – MrPersson Dec 23 '20 at 14:39
  • I will keep Go in mind in the future if the servers are shown to be too slow. – MrPersson Dec 23 '20 at 14:41
  • You have two modules (Login and Lobby) defined as separate entities. As they can be hosted by dedicated server they easily can be implemented via serverless approach. You ask how it solves. The main thing here is you need no thinking about infrastructure stuff like load balancing, resources lack and so on. It's covered by provider. All the services you develop including database are "infinitely" (we can use this term with assumption of your project required resources) scalable. For login also you can use Amazon Cognito. They provide 40k logins free. – 4xy Dec 23 '20 at 15:09
  • The success way is to use ready services as much as possible and do not waste time inventing bicycle. About delay between continents. The transcontinental optical channels that links huge providers are very fast. I don't know exactly, I had no such needs, but I think you are not the only person who encountered such an issue. I suppose the solution within these techniques is already exist. Just necessary to investigate deeply. – 4xy Dec 23 '20 at 15:14
  • After spending many hours today researching everything regarding AWS and my problem, it seems that using AWS is actually the solution like you said. This will be very nice to know for later in the development, thank you! There are many problems with AWS that has to be solved first, such as Steam logins seems to be a bit harder to implement and that their services have to be split into different regions, etc. But this is probably the best solution for scalability, even if it would require weeks of work. Also, DynamoDB seems to be the solution for a world-wide database. – MrPersson Dec 23 '20 at 21:18
  • You are welcome! I think these will work nice for you. Also to make more comprehensive conclusion consider searching and inspecting another providers not only Amazon. May be you will find something that fits better for your needs than Amazon. – 4xy Dec 24 '20 at 10:27
0

Well, this is c++ and i code in java, but maybe the logic is useful for you any way so i will tell you how i end up implementing something similar but in a casino.

In my case I have 2 diferrent sockets in the same server program, one of the sockets is TCP and it handles all logins, registers and payments, while the second socket is UDP and it handle the actual game multiple payers are playing, then you could group internally all those UDP connection in groups (probably arrays of sockets) to generate those lobbies. Doing that all your server is just one class that could run in a single pc using 2 ports (one for each socket) However this do not solve the problem of the ping for people who live far away. If ping is a problem (not my case in a casino) you could probably host your server region base but removing the login, registration and paymets of your server and replace it for a connection to a central server (this central server should be TCP and you could also implement a https socket to also allow your webpage to connect to this server and create accounts or pay you directly from the browser)

sorry to mess your life even more, but i hope it helps

tomazu07
  • 3
  • 4
  • Thank you for your reply! So the only change would be to make the login and lobby server use TCP instead of UDP in that case? Since UDP is already used on the actual game (the game server). Also, does TCP help a lot compared to UDP in these cases? What is a central server? How does that solve players who live far away? – MrPersson Dec 23 '20 at 14:28
  • @MrPersson Well i would say you need more than only that change, in the first place you don´t need a separete server only for lobbies, a single server can host both the login system and the lobbies, however, logins and paymets should allways be hosted over a TCP connection because UDP does not garantee the arrival of the package, and that is a big problem in a login or a payment (in fact you should probably use a SSL socket over TCP to truly secure that connection). – tomazu07 Dec 23 '20 at 20:39
  • @MrPersson Nither of previous thing will help with ping, but both are mandotory if you want your connection to be safe. In case you want to reduce ping, just host game servers region base (which should use UDP to reduce latency) and make those server to report to your central server via TCP (so no report is lost). A central server is the server that will connect to your dataBase and will truly have access to important information (in this case is the server that hangle logins, payments and the lobbie system) – tomazu07 Dec 23 '20 at 20:39
  • I did start up with a single server for the login and lobby server, but my thoughts were that they could be hosted on different computers with different internet connection, that way I split the required packets by half, which is a very good start if I believe they will be bottlenecks. UDP using ENet is almost exactly like TCP, they are garanteed. Payments are through https using paypal on my website, and my login server uses SHA password hashes with salt that are temporary. I could easily add encryption to each package as well. My problem is not with the security. – MrPersson Dec 23 '20 at 21:01
  • Also, a central server would in that case be bad if it is in just one location (and using one database), as it is not scalable. – MrPersson Dec 23 '20 at 21:02
  • @MrPersson Well, fistly I don´t know why you belive having a central server would be a problem, you need that to show all lobbies in all regions, and also if the server is only recieving logins and notifications from the game servers then you would need more than a million game servers to actually cause any trouble for your central server, and if you manage to make your game that popular then you will already be rich. If you have a central server your bottleneck will not be the amount of users but the amount of game servers. Also, i would still use TCP for logins but that is up to you. – tomazu07 Dec 24 '20 at 05:16