Topic : What is Lag?
Author : Geoff Howland
Page : 1 Next >>
Go to page :

What is Lag?
by Geoff Howland

Lag is the bane of Internet gameplay, but what is it?

Latency is the proper name for the time it takes a packet of information to be sent from the sender to the receiver over a network. Lag is what is it generally called and more specifically when it is noticeable. If the latency is low, you don't notice any lag, the longer it takes a packet to cross the network, the more lag you have.

To understand why you have lag you need to understand how information is sent.

The Packet
When information needs to be sent from your computer it first needs to be chopped up into small pieces, these pieces are called packets. Your computer cant send all its information at once because you cant be guaranteed that no one else will try to send information at the same time and cut off your transmission. Basically networks or any type of computer connection work just like a phone conversation you would have with a friend. If you both talk at the same time, it's hard to understand what is being said clearly. If one of you talks and the other listens, then it's easy to understand what each other is saying.

One of the key things to understand about packets is that the longer the packets are, the longer it will take to send and the more likely you will be interrupted by someone else. If you are interrupted you have to wait for a little while, in which the network controller hopes the interrupting transmission has finished, and then you send the packet again. When another packet interrupts your packet it is called a collision.

The more often you have collisions, the more lag you will have and collisions are extremely common on the Internet as you have billions of packets of information being sent all over the world, all the time.

The Ping
A "ping" is both a term and a program used to determine how quickly a packet can go to the destination and the destination can send a response back that it got the packet, so it is measuring a round trip of information. Ping times vary tremendously by what type of connection you have to your network, how close you are to your destination and how much other information is trying to be sent by other people at the same time.

On a Local Area Network (LAN), that is a system of computers tied together all in one basic location like a house or office, you can receive extremely fast responses, usually less then 10 milliseconds if there is not a lot of transfers happening. In an environment like this you will probably never notice a lag unless someone starts doing one or more huge file transfers.

If you are connecting to the Internet through a dial-in modem to an ISP (Internet Server Provider), as most home users are, then you will receive much higher ping times because your connection is hundreds of times slower than a LAN. Games are however usually designed so that they will still work well on a dial-up Internet connection, but there are a lot of factors that go in to the connection moving smoothly.

Connection Speed
The first thing that will limit your network connection is the speed at which your computer can talk to your ISP. Most modems today are at least 28.8K BAUD to 56K BAUD. BAUD means bits per second, and does not stand for anything, it was named after an engineer name Baudot. A bit is one switch that is either "on" or "off". To have enough information for a single character you need 8 bits, which equal a byte. However, because you are sending the information over a modem, you have to add on extra information so that the receiver knows he is listening to you correctly, so it actually takes 10 bits to send 1 byte. This makes calculating how many bytes you are sending easy however, as you just need to divide 28800 bits/second (28.8K BAUD) by 10 and end up with 2880 bytes per second.

Although you may have a modem that say it is a 56K BAUD modem, it is unlikely you will ever receive rates higher than about 3400 bytes per second. When you do receive more it is usually because your modem is compressing the information sent, and when you download information that is already compressed or is not very compressible, you will not get those extra bursts of speed above about 3400 bytes/second.

Enough of the history lesson, lets get into where this matters: the lag.

Birth of Lag: Building the Packet
The first "bottleneck" where you will have problems sending and receiving information will be your modem. Your modem sends approximately 3400 bytes per second, your game will often update the screen to show you new visual information 30 times per second, or more.

However, it is not necessary to update the network connection this quickly, as real movements and actions do not change as quickly as the eye can detect most often. Normally you will not need to have the network connection updated more than 10 times per second, leaving approximately 340 bytes per update in an ideal environment.

To understand exactly what 340 bytes per update means, you need to understand what kind of information needs to be updated in the game and how many bytes each one of those pieces of information will take.

Say we take a game like Quake, where you are able to turn in different directions, move in different directions, jump and shoot. Lets say we take just this information and try to update it and send it back and forth between the players. I won't bore anyone with more lessons on how computers operate at a low level, so you're just going to have to trust me on the math stuff unless you want to learn about it more or you already know it.

First we will start by determining what direction the player is looking, so that we can tell the other player's computer how to draw which direction your player is facing.

If we have less than 256 directions the unit could be facing, then we can fit it into 1 byte. Most likely the game allows for more than this, but we can fudge it so that it looks correct enough on the other persons display so that this will be fine. If we store the direction a player could be looking up or down we will need an additional byte. This means we have 2 bytes that will need to be sent every update for the characters facing information.

Now we have the direction and speed/distance you are moving. To make this easier we can just send what game developers call a "delta", which in math they use to mean a change, so we will just send the changes in coordinates from the last position. To update the unit's position in the 3 axis's X , Y and Z we will need 2 bytes each to store a change of up to 64,000 unit positions in any axis. If we can shrink this movement down to be limited to a 256 unit change we can reduce the bytes needed from 6 to 3, but for arguments sake we will say we cant, so we need 6 bytes bringing the current total to 8 bytes.

To figure out when the unit jumps a lot is left up to the user, as they may let go at any time, so we will just turn on a flag that says it unit is jumping and at what height position they are currently at. If the user lets go before we update again, it will be less of a mistake then if we only update where the unit's current height is, as you can only jump so high. So we add on another two bytes for the time the user pressed jump, which brings us to the total of 10.

We'll use another byte to add on the time a weapon was fired and we also have to pass on what kind of gun we are using so that the other computer knows what type of projectile to attack with which will take 3 bytes, bringing us to 13 bytes.

Assuming that there can be 8 players at any time in a multiplayer game, we need to be able to send 104 bytes per update to give just this minimal information for each of their actions. There are a few more areas that need to be covered for players as well as some server synchronization items, but we will leave those out for this discussion.

These 104 bytes needs to be sent over the Internet through a protocol, and the one most games use it called UDP, which takes up 8 bytes to address information about the packet and where it is coming from and going. So to travel over the Internet our packet would need to be a grand total of 112 bytes,

Page : 1 Next >>