Jump to content
  • Advertisement
Sign in to follow this  
blueginger

Session-based game server programming

This topic is 3126 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I was wondering about some game server framework issues. Lets say in the context of a session-based game. eg. counter strike, etc. Whenever a new game is initiated, would every game session be created as a separate thread on the game server? Or would it be more efficient running all the game sessions sequentially but time slicing it. Meaning if the game is to be run at 30fps and there are 500 game sessions on a single server. I will go thru all the game sessions and spending just (1000/30)/500 = 0.067ms on each tick of each game session. So on one pass i would update the ticks of all the game sessions. Which is better or is there other ways of updating the game sessions. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
It basically comes down to what works best for your needs.

I belive counter-strike is a user hosted server soo each server is its own isntance of the server which handles data from only one active game..


Something to keep in mind is just because one person does it one way doesnt mean you HAVE to do it that way.. if you come up with a way that works for what you need then that is all that matters. I would suggest programming it the way you think is the best feasible plan for your game and do testing.. if not then refactor and change things.

My server right now has the concept of "rooms" and "users" a room can be a "game room" "chat room" ... and well i just need the basic user right now (even tho it can be extended later)... i then have a state manager built in to know what users are in what room and what room has what users and all that jazz.. so when the server recvs data from a user it does a state lookup and find the proper room and sends that data to the room to be processed and sent back out , or if the room has periodic data to send out to all current users of the room it can do a state lookup to find its users and send it. With my server setup my server can run multiple "games/chat" on one server .... It works for what I am doing and if i find that later on it didnt scale well or it doesnt meet my needs now it has been designed in a way that i can easily change it.

Just research what you want to do and try it... if you want to multi thread to do it then try that.. if you want to use asnyc try that... if you want to do sequential try that.

Share this post


Link to post
Share on other sites
My guess is, the easiest solution would be to run multiple instances of the executable, each using a different server port. I used that 'solution' for stress-testing a 16 player game, and could run 8 clients (console app bots) and a server (another console app) per computer.

If you use one exe, multiple threads, you will have more control about how to balance the CPU among all your sessions. Else, you're pretty much dependent on the OS and how it prioritises processes.

time slicing on a single thread wouldn't be that efficient, unless you have a very limited number of sessions (I use a 'party' and a 'game session, all on the main thread, but wouldn't do that if I had half a dozen sessions running especially with current multicore and multithread technology).

Share this post


Link to post
Share on other sites
Quote:
Original post by blueginger

Meaning if the game is to be run at 30fps and there are 500 game sessions on a single server. I will go thru all the game sessions and spending just (1000/30)/500 = 0.067ms on each tick of each game session. So on one pass i would update the ticks of all the game sessions.


I'm not sure you can do a tick in 0.067ms for something like CS. That is meager ~200000 CPU cycles per tick.

A cache miss can cost you 200 ticks - and there would be many (just a single cache miss per thread = 100,000 cycles, 50% of budget). According to some numbers, thread context switch takes 4000 cycles. Since there would be 500 mandatory context switches, this adds up to 500*4000 = 2 million cycles. Or, 10 times more than you have the budget.

Threaded servers are used with some success in web apps, where they act as buffer. If several requests take too long, more threads are spawned or pooled. Apparently, some of google's servers juggle up to 5000 threads, but not without considerable effort and possibly custom kernel hacks.

So no, the numbers simply don't add up. And besides, 500 sessions (threaded or not) is only possible for something computationally trivial, such as card games, but definitely not for low-latency high-CPU. You might be able to get away with a single-digit number of sessions per core.

Share this post


Link to post
Share on other sites
Thanks for the replies guys.


So from your replies, i gathered that one server would at most be able to host less than 10 number of game sessions if it were a low latency high CPU game like counter strike.

Recently i saw games like League of Legends and Heroes of Newerth in which they have a dedicated server for hosting the game sessions and not on the players' computer. These games are similar to DOTA(RTS-style play) where a single unit is ordered around the map via mouse clicks.

So for these types of game, would you say the number of game sessions a game server can hold is the same as counter strike (less than 10)?

Share this post


Link to post
Share on other sites
It all depends on your design... If you are designing a p2p where one of the clients in the game is acting as the server as well you will ussally have lower max players to preserve the playability... Now if you creating dedicated servers its all in how you design it.. Delta Force Land Warrior was very much like counter strike and you had 32 player teams .... so its all about your design.. Think of what you want then figure out how to do it.

Share this post


Link to post
Share on other sites
For an RTS that's using the input-synchronous model, the server doesn't need to do any computation; it only needs to forward data between players.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!