Slashdot Mirror


UDP - Packet Loss in Real Life?

PacketStorm asks: "There's always an argument between TCP and UDP users. TCP users complain that UDP is non-determinstic and lossy, while UDP users complain that TCP is slower and nobody needs all the features anyway. So the question is - has anyone actually seen/experienced UDP loss in high-traffic environments? Is the degeneration of UDP any better or worse than TCP in a congested environment? TCP also craps out in times of congestion, but at least you know - or do you? Experiences?"

19 of 127 comments (clear)

  1. both are usefull by f0rtytw0 · · Score: 4, Insightful

    UDP for streaminig video and games and other sorts of things where it doesn't matter if you miss a couple of packets and TCP where you can't miss packets such as file transfers. There everyone happy go home now.

    --
    this is the most important sig ever! In your face 446154!
  2. Parts of the Internet currently collapsing? by Anonymous Coward · · Score: 4, Funny
  3. Why UDP in games, TCP for bulk tranfer by MonMotha · · Score: 5, Informative

    UDP is commonly used in games and other time sensitive environments precisely because it lacks reliabilty. With time sensitive data (such as streaming video or unit positions in a game), if the data gets dropped it's not worth it to retransmit, because it woudl be out of date. Therefore, the program just transmits the next update and the user sees a small skip. This is better than getting "out of sync".

    TCP is designed to make unreliable networks (like the internet, which only gives "best effort delivery") reliable by ensuring that a stream can be reassembled, in order, with no missing pieces. Read the RFC for more info here. This reliability makes it good for things that need zero corruption (file transfers for example), and aren't time criticial.

    Hope this helps.

    --MonMotha

  4. Re:UDP packet loss by Polo · · Score: 3, Informative

    Hmmm... it's LOTS easier to write an application to handle UDP than to handle TCP.

    With TCP, you have a listening socket and then a socket for each client. Each socket has a file descriptor, and you have to select() on all of them to check for activity. There is a lot of housekeeping to do - though it is a solved problem - all webservers solve it. Timeouts are harder to determine from the application's perspective because there can be retransmits and stuff going on that you have no idea about.

    However, with UDP, it's laughably easy. You just do one recvfrom() and you get a packet and it also fills in a data structure to tell you where it came from. No filling in fd_set structures and no running out of file descriptors. When you got the packet, you got it.

    Most online games and stuff would really like to know when packets were sent, when they were received and if packets are being dropped. With UDP you can usually find out these values directly. With TCP I think it would be more like an educated guess.

    One drawback is that UDP is quite easy to spoof. I can send a packet and it is up to the application to figure out it has been spoofed.

    If I were downloading a patch to a game I think TCP would be the better choice. It already has the smarts to pace the connection, transmit the data reliably and prevent spoofing.

  5. UDP Experience by mchappee · · Score: 4, Interesting

    I'm firmly in the UDP camp. About 4 years ago we replaced our timeclocks at work (manufacturing facility) with hardened, wall-mounted PCs. I wrote a GTK app that started at boot up that takes the users card swipe, grabs their name from the database (for display only), and sends the clock number via UDP to the timeclock server.

    During my initial proposal I mentioned to the PHBs that I would use the UDP protocol. One of my colleagues, wanting to sound important, said that UDP can be lossy. He went on to explain packet loss to the befuddled crowd. Well, the PHBs latched onto the term "packet loss". Packet loss this, packet loss that. They had no freakin' clue what it was, but it sounds pretty cool.

    Anyway, I had to set up a test in which I had all of the timeclocks start a program at the same time. This program went into a tight loop of sending UDP packets (clock numbers) across the network to the server. Each one sent 1000 clock numbers, and every single one made it across. Obviously our 100mb network and proper use of subnets helped, but we haven't experienced any packet loss in the four years that these things have been running. So there. :-)

    Matthew

    --
    /. finds me to be 20% Troll, 80% Funny
  6. Definitely by austad · · Score: 5, Informative

    I run a cluster of high volume mail servers that use syslog-ng to log to a remote syslog server. This reduces disk IO for each message and actually gives a very noticable performance increase. However, I noticed under periods of very high volume, I was losing nearly 50% of my log entries. Syslog-ng has the ability to use TCP for logging, so I switched, and I haven't lost any entries yet.

    UDP is great for things you that aren't useful if retransmitted later, like real time apps (Quake, video streams, audio streams, etc.) But to ensure no loss at all, you need to use TCP.

    --
    Need Free Juniper/NetScreen Support? JuniperForum
  7. What argument? by jkujawa · · Score: 4, Insightful

    Jesus. Both have their uses. You use TCP if you need the reliability, and a stateful connection. You use UDP if it doesn't matter that a packet gets dropped here or there. Things like games and streaming media are good examples. This is rather like comparing Pepsi to milk. They both have their place. It's the job of a good engineer to determine which is most apropriate.

    1. Re:What argument? by tunah · · Score: 3, Funny
      This is rather like comparing Pepsi to milk. They both have their place.

      Except for pepsi.

      --
      Free Java games for your phone: Tontie, Sokoban
  8. Re:UDP packet loss by Jeremi · · Score: 5, Insightful
    However, with UDP, it's laughably easy. You just do one recvfrom() and you get a packet and it also fills in a data structure to tell you where it came from.

    ... or maybe you don't get the packet, because a router was loaded down and had to drop it. Now you gotta implement a timeout and retransmit protocol. Not to mention that packets may arrive out-of-order from the way they were sent, so you if ordering is important (and it usually is) you have to implement some sort of sequencing tag systems too. A few dozen hours later, you find out you've implemented something that looks suspiciously like a primitive version of TCP... :^)

    --


    I don't care if it's 90,000 hectares. That lake was not my doing.
  9. Re:UDP Experience QWZX by Anonymous Coward · · Score: 5, Insightful

    /me bangs his head on his desk over and over at the sheer stupidity of this.

    Dude, I hate sound flame-y, but do you have any understanding of what you implemented? That you got lucky and it "works" is totally irrelevent to the fact that it's completely unreliable. All it takes is one flakey piece of Ethernet dropping packets to SCREW UP FREAKING TIMESHEETS.

    This reminds me of the morons who use MySQL for financial transactions (i.e., no transactions, no foreign keys, etc) who justify their ignorance with "well, it works so far!!"

    They point isn't whether it works or not, the point is that when it fails, it fails spectacularly. Like your system. Just because you can keep spinning the chamber and the russian roulette gun never goes off doesn't mean it never will.

    Seriously, you screwed up bad. These are the kinds of stories that really make me think that programmers should have some sort of licensing.

  10. Re:UDP packet loss by Polo · · Score: 3, Informative

    Well, in relation to the post about anarchy online I replied to, it seems like TCP didn't work.

    I would think SOME game data would need to be reliable, but most isn't. The problem with TCP for an online game is that you can never THROW AWAY data that's too old or unnecessary. It will be transmitted and retransmitted further delaying current data. At some point, things will become unusable.

    I don't think you could play a multi-user game for over an hour and not run into this problem. I think on lower-bandwidth connections, you might never be able to catch up once you fall behind.

    Of course, you could do what microsoft does with DirectPlay: open multiple connections, sometimes on multiple protocols, some of them asymmetrical, while ignoring silly details like firewalls and NAT.

    I think the initial handshake for dungeon siege was something like:

    first packet: udp my_ip:6073 to server_ip:6073
    reply packet: udp server_ip:6073 to my_ip:2302 (what!?!?)
    next packet: udp my_ip:2302 to server:6073

    or some garbage like that. I think the dungeon siege guys just changed it.

  11. Re:UDP packet loss by crisco · · Score: 3, Informative
    Many games are designed to not care about the dropped packets. Sure, they can be unplayable if packetloss gets too high but the occasional dropped packet doesn't matter.

    Some tasty articles from gamasutra (might require a login, you might also find these in Google's cache):
    "TCP is evil. Don't use TCP for a game. You would rather spend the rest of your life watching Titanic over and over in a theater full of 13 year old girls."
    article on WON's servers for Half-Life.
    Dead Reckoning Latency Hiding for Multiplayer Games.

    Other software might need the benefits of TCP, but game development is one familiar illustration of where UDP often wins out.

    --

    Bleh!

  12. So, what you're saying is... by Wonko42 · · Score: 4, Funny

    I'm a skydiver. I never use a parachute. Instead, I just jump out of planes and hope that I land on a large air mattress. It's worked perfectly so far. Why should I switch? All you silly fools using parachutes make me laugh.

  13. In most cases using UDP is a loss by WolfWithoutAClause · · Score: 4, Informative
    If you have very special requirements, or very non special requirements, or you simply can't use TCP for some reason, then UDP can give you better performance. But it usually won't.

    About the only reason for using UDP is if you deliberately want to circumvent the congestion avoidance protocols that are built into TCP. So, if you are playing a game, and you need the packets to get through at all costs, but you aren't sending many packets- by using UDP you can agressively defend the small amount of bandwidth you need- any TCP connections around will tend to back off and get out of your way; and that's reasonable if you code it carefully. But writing the protocol to do that is hard, you have to understand not only UDP but also TCP, as well as your game requirements.

    And that's the real problem. In most cases people think that waving UDP at the problem will solve their problems- in fact it makes them worse; and TCP has solutions to problems only PhDs have even thought of, and the solutions are built in.

    As an example, somebody I know implemented a tftp protocol using UDP. The guy is off the chart in his software abilities (trust me the guy is amazing, he's in the top 2 percent of software engineers according to the tests). Anyway in a back-back comparison against a standard ftp protocol- the tftp protocol loses by a factor of 10 or more (on a network with some congestion, I expect a quiescent network would have been much more level). Of course tftp isn't supposed to handle congestion. But that's the problem- UDP can't handle network congestion out of the box... indeed if anything it tends to create network congestion.

    The main algorithms in tcp include 'slow start' and 'exponential backoff'. Both of these are missing in UDP, and both improve the network performance enormously. If your application doesn't affect network performance and doesn't worry about packet loss much, then UDP may be the way to go, otherwise stay away from UDP.

    --

    -WolfWithoutAClause

    "Gravity is only a theory, not a fact!"
  14. Interestin paper on Checksums, CRCs by d-rock · · Score: 4, Informative

    This is a very interesting paper on why things don't always work like we think they should...

    Derek

    --
    Don't Panic...
  15. Lemme get this straight. by FreeLinux · · Score: 3, Funny

    NTP was too complicated(??) so, you designed built and tested your own homegrown version of NTP??????

    To quote Dr. Evil, "Riiiight...".

  16. Coding philosophy by kevin42 · · Score: 3, Insightful

    I've spent the past several years writing networking applications, and this is my philosophy: Anytime there is *any* chance of a packet being lost or arriving out of order, you must write code that assumes every packet has a high probability of being lost. I've seen people make assumptions that since it's running on an ethernet lan they will never lose UDP packets, then their app becomes very unstable. Even when sending UDP packets to localhost they can be lost. When designing UDP software it shouldn't be a matter of how often packets are lost, but how well your code deals with lost packets.
    Now if only someone would standardize a reliable datagram protocol implementation. :)

  17. Re:UDP Experience QWZX by RobinH · · Score: 3, Insightful

    Dude, I hate sound flame-y, but do you have any understanding of what you implemented? That you got lucky and it "works" is totally irrelevent to the fact that it's completely unreliable. All it takes is one flakey piece of Ethernet dropping packets to SCREW UP FREAKING TIMESHEETS.

    Ok, calm down...

    Now, I agree that UDP is built to be a fast, not-so-reliable protocol. One would initially presume that this is not the best thing to use on a punchclock system.

    However, you have to look at the whole system.

    First of all, if you put all the punchclocks, and the servers on the same subnet, then you've eliminated dropped packets due to routing.

    Secondly, if you send an acknowledgement back to the clock, then it can display to the user "OK, you're signed in" or "ERROR, please retry". If you lose either the "sign-in" packet, or the acknowledgement packet, then all the user has to do it swipe again to retry.

    Thirdly, these kind of systems always (should) have a manual backup, so if, for some reason, the system records Buddy punching in at 7 am, but never punching out, then a supervisor can go in and manually update the database to fix the problem.

    Just remember that programs like this don't exist in a vaccuum; they are always part of a larger picture, and they need to function in that framework.

    --
    "I have never let my schooling interfere with my education." - Mark Twain
  18. Re:UDP Experience QWZX by bugg · · Score: 3, Insightful
    Secondly, if you send an acknowledgement back to the clock, then it can display to the user "OK, you're signed in" or "ERROR, please retry". If you lose either the "sign-in" packet, or the acknowledgement packet, then all the user has to do it swipe again to retry.

    As a rule, people who build acknoweldgements into their UDP based protocol should have used TCP.

    --
    -bugg