Server-Side Concept, Brief Explanation?

Started by
9 comments, last by cr88192 11 years, 1 month ago

Small nitpick: UDP is not faster, at least not measurably. UDP has a lower latency because there is no in-order delivery of a stream, but there are individual packets. A packet arrives or doesn't arrive. Or, it gets delayed and arrives some time later. TCP will do its best to deliver everything in order, waiting and resending as needed.

I think TCP is slower, but not because of larger headers.

When you send a large file as fast as possible with TCP it fills whole large packets of same maximized size, even if you call the send with uneven or small data. Thats what its made for, optimizing bandwidth usage in this case.

When you have a game you typically try to send only tiny updates at some regular interval. When you use TCP for that it gets a tiny message, thinks it doesnt have enough to fill a packet and waits uselessly until the timeout, then it needs to send the tiny package anyway and shortly after that your game wants to send a tiny message again and it waits again uselessly. If you sometimes send a large packet it will get split up and then wait for the timeout before sending the second part of it and the other end got to wait when it cant use the first part alone.

Now if you dont disable the nagle algorithm it gets much worse and it basically doubles latency because it always does not send the ack back cause it waits for a second incoming packet which will nearly never come in time for such a game. I know some popular MMORPGs did not even use the no delay option to disable the nagle algorithm, which made people suffer much more from lag, which lead to them tweaking the registry or even using paid proxy services like lowerping after they found out.

When you send a UDP packet its immediately send out, no waiting, no tweaking needed. You just need to resend lost packets manually when it was a packet that had to reliably delivered, which is more programming work.

That said I think people should really try to find some middle of the road protocol that combines some of the speed of UDP with the easiness of TCP and optional sending of reliable packets. With some googling you probably find something like that, but not as standardized as people probably reinvent this regularly when not going the easy way of TCP.

Advertisement


Small nitpick: UDP is not faster, at least not measurably. UDP has a lower latency because there is no in-order delivery of a stream, but there are individual packets. A packet arrives or doesn't arrive. Or, it gets delayed and arrives some time later. TCP will do its best to deliver everything in order, waiting and resending as needed.

I think TCP is slower, but not because of larger headers.


When you send a large file as fast as possible with TCP it fills whole large packets of same maximized size, even if you call the send with uneven or small data. Thats what its made for, optimizing bandwidth usage in this case.

When you have a game you typically try to send only tiny updates at some regular interval. When you use TCP for that it gets a tiny message, thinks it doesnt have enough to fill a packet and waits uselessly until the timeout, then it needs to send the tiny package anyway and shortly after that your game wants to send a tiny message again and it waits again uselessly. If you sometimes send a large packet it will get split up and then wait for the timeout before sending the second part of it and the other end got to wait when it cant use the first part alone.
Now if you dont disable the nagle algorithm it gets much worse and it basically doubles latency because it always does not send the ack back cause it waits for a second incoming packet which will nearly never come in time for such a game. I know some popular MMORPGs did not even use the no delay option to disable the nagle algorithm, which made people suffer much more from lag, which lead to them tweaking the registry or even using paid proxy services like lowerping after they found out.

When you send a UDP packet its immediately send out, no waiting, no tweaking needed. You just need to resend lost packets manually when it was a packet that had to reliably delivered, which is more programming work.

That said I think people should really try to find some middle of the road protocol that combines some of the speed of UDP with the easiness of TCP and optional sending of reliable packets. With some googling you probably find something like that, but not as standardized as people probably reinvent this regularly when not going the easy way of TCP.


this is why people typically disable Nagle...

if Nagle is enabled, TCP will buffer things, and send packets when the buffer fills up to a certain amount.

if Nagle is disabled, it will generally send things immediately, which is better for latency, but also makes it a good idea to write the whole message to the socket as a single operation.

As far as I remember there is still some buffering in TCP even if you disable nagle, it only prevents the "optimization" of only wanting to send an ack for every 2 incoming packets which interacts badly with other algorithms in TCP.

http://en.wikipedia.org/wiki/Nagle%27s_algorithm

This topic is closed to new replies.

Advertisement