[Dev Blog] Server Tick Rates

In a previous post I wrote about the naive authoritative server solution I implemented for my fledgling multiplayer game. I have the server set up so that all incoming commands (requests, really) from the client are processed and responded to in real-time. While this method works for the small number of simultaneously connected clients I can test at any given time, it doesn’t scale well for larger numbers of clients. For instance, during player movement the client sends commands repeatedly while the arrow keys are held down. With a handful of connected clients the server can easily respond to every client as their commands are accepted, but as the number of clients increases, the amount of data being sent back and forth can completely saturate the connection. The solution is to limit the rate at which the server responds to commands.

Most servers of multiplayer games have what is called a tick rate – the rate at which a server sends updates to a connected client. The faster the tick rate, the more updates a client receives and as a result the client’s representation of the game state is closer to the state on the server. The type of game you’re making generally dictates the tick rate. Fast-paced action games that require fast reflexes and precision like first person shooters will require a higher tick rate so the client can react faster to changes in state. Slower-paced games like role playing games can get away with a lower tick rate, especially if combat is turn-based. For my game, since I’m using Node.js, I can implement the tick rate using the setInterval method. It will likely look something like:

In addition to updating clients, the server will have a separate rate for simulating the game world. Generally the game world will be simulated and updated at a faster rate than client updates. If I’m trying to target a frame rate of 60fps, the server has to complete its processing per update call in roughly 16 milliseconds (16 milliseconds per frame means 16 * 60 = 960 milliseconds to process 60 frames). For the simulation update I’ll have a similar set up as above but with an interval of 16.

Programming With Math Made Easy

I never found memorizing physics formulas to solve silly problems about cars driving up hills and slipping on ice particularly compelling. What is cool is adapting these formulas and using them in code to make physics simulations. I can’t recommend the book The Nature of Code enough for learning how to turn physics formulas into observable examples. I’ve been using the wonderful Codea app on my iPad to write all the simulations. The examples in the book are written in Processing and Codea uses Lua so a little conversion needs to be done.

Storing Map Tile Information Using Binary in JavaScript

For the MMO (“massively” being used very loosely here) I’m working on, the server and client communicate using TCP by sending plain English words to each other. I know this is inefficient but it makes the code more readable when you see a command of “MOVE” instead of “101”. I’ll switch over to binary eventually and use this article on representing map tile information in binary as a reference.

Interview Programming Questions

LeetCode OJ is a platform for preparing technical coding interviews. Pick from an expanding library of more than 190 questions, code and submit your solution to see if you have solved it correctly.

Algorithms are definitely my weakest skill so this is going to be good practice for future interviews.