A real-life example of the imporance of counting the number of bytes per packet (from a Gamasutra article that just went up).
Points to note:
- Xbox inflates the header sizes for packets
- Elsewhere in the article it’s revealed that Xbox’s TCP implementation is fatally flawed: it drops a lot of TCP connections. This allegedly breaks TCP’s “guaranteed delivery”, although I suspect that they were in fact using the API’s / protocol slightly wrongly (note the first para ). They claim the flaw is due to Xbox’s memory-management, but I wouldn’t be surprised if MS fixes this; it doesn’t sound so permanent a problem as they make out.
"This is where I display my lack of experience in network programming, as I’m sure it will be common knowledge to anyone familiar with such things. At the start of the project I understood in an intellectual sense that packet headers could be expensive, but it wasn’t until I started working out some actual numbers that I realized the scope of the issue.
A standard UDP header is 28 bytes, and a TCP header is 40 bytes. On Xbox they are larger, due to the overhead of the packet encryption and NAT traversal, requiring 44 bytes for a UDP header or 56 for TCP.
This may not seem like much at first, but consider the case of 16 players sitting in a lobby talking to each other. MotoGP uses a 40 millisecond granularity on the voice compression, which outputs an 18-byte chunk of speech data. 18 bytes times 25 packets a second times 15 listeners gives a total data rate of 53 kbps, but if you add in the UDP header sizes, this goes up to 182 kbps. That is an overhead of 243%, and makes the difference between meeting or missing our target of working over a 64 kbps connection.
Obviously, you don’t actually need to send voice data every 40 milliseconds. The tradeoff is that the longer you buffer it up, the more latency you introduce, but also the less space you waste on packet headers. In MotoGP we send voice packets 4 times a second, which gives a 73 kbps data rate, 38% packet overhead. That’s still slightly over our 64 kbps target, but not by so much that I can’t get away with ignoring the math and pretending it is OK!
With so much of the total bandwidth wasted on packet headers, it is crucially important to minimize this in every way you can. Never send two packets where one will do. If you have a bit of data that you’d ideally like to send this frame, consider whether you might be able to hold it back for a while and then merge it in with some other information that is due to be sent in the near future.
Don’t mix TCP and UDP. If you send some data by one and some by the other, you won’t be able to merge packets, so you’ll end up paying twice the header overhead. Even if you have to increase the payload size in order to do this, you can reduce the overall bandwidth usage by combining everything into a single protocol. Since TCP is unsuitable for game data and voice packets, in practice this means you should use UDP (or the Xbox VDP equivalent) for everything.
Once you have all your packets running over the same protocol, make sure they all use the same port, too. That minimises resource usage, and due to an optimisation in the Xbox network stack implementation, if you put everything on port 1000 you can save four bytes per packet, too."
Link to full article: