views:

4800

answers:

10

If you have a situation where a TCP connection is potentially too slow and a UDP 'connection' is potentially too unreliable what do you use? There are various standard reliable UDP protocols out there, what experiences do you have with them?

Please discuss one protocol per reply and if someone else has already mentioned the one you use then consider voting them up and using a comment to elaborate if required.

I'm interested in the various options here, of which TCP is at one end of the scale and UDP is at the other. Various reliable UDP options are available and each brings some elements of TCP to UDP.

I know that often TCP is the correct choice but having a list of the alternatives is often useful in helping one come to that conclusion. Things like Enet, RUDP, etc that are built on UDP have various pros and cons, have you used them, what are your experiences?

For the avoidance of doubt there is no more information, this is a hypothetical question and one that I hoped would elicit a list of responses that detailed the various options and alternatives available to someone who needs to make a decision.

+6  A: 

ENET - http://enet.bespin.org/

I've worked with ENET as a reliable UDP protocol and written an asynchronous sockets friendly version for a client of mine who is using it in their servers. It works quite nicely but I don't like the overhead that the peer to peer ping adds to otherwise idle connections; when you have lots of connections pinging all of them regularly is a lot of busy work.

ENET gives you the option to send multiple 'channels' of data and for the data sent to be unreliable, reliable or sequenced. It also includes the aforementioned peer to peer ping which acts as a keep alive.

Len Holgate
+8  A: 

It's difficult to answer this question without some additional information on the domain of the problem. For example, what volume of data are you using? How often? What is the nature of the data? (eg. is it unique, one off data? Or is it a stream of sample data? etc.) What platform are you developing for? (eg. desktop/server/embedded) To determine what you mean by "too slow", what network medium are you using?

But in (very!) general terms I think you're going to have to try really hard to beat tcp for speed, unless you can make some hard assumptions about the data that you're trying to send.

For example, if the data that you're trying to send is such that you can tolerate the loss of a single packet (eg. regularly sampled data where the sampling rate is significantly higher than the nyquist rate) then you can probably sacrifice some reliability of transmission by ensuring that you can detect data corruption (eg. through the use of a good crc)

But if you cannot tolerate the loss of a single packet, then you're going to have to start introducing the types of techniques for reliability that tcp already has. And, without putting in a reasonable amount of work, you may find that you're starting to build those elements into a user-space solution with all of the inherent speed issues to go with it.

Andrew Edgecombe
Ok, I'll adjust the question. I'm more interested in the pros and cons of the various reliable UDP protocols out there rather than a 'use TCP' response ;)
Len Holgate
@Andrew - it's very EASY to beat TCP in two cases: (1) your application has lighter reliability requirements than "all data, always in order, no duplicates, no excessive queueing". Or (2) you are using multicast. Reliable UDP is very common for multicast environments.
Tom
Also, TCP suffers horribly when used across a WAN connection (long haul issues). Why, simple. TCP uses windows where the packets in the window have to be ack'd. ACK protocols suffer because of latency due to line distance. Google: WAN TCP "speed of light"
Ajaxx
@Ajaxx, you are very correct around this, however, TCP/IP does this purposely because of the last internet meltdown. If you are doing high bit rate protocol without any congestion control, well basically shame on you. If you own the network, then go wild.
Kevin Nisbet
+8  A: 

What about SCTP. It's a standard protocol by the IETF (RFC 4960)

It has chunking capability which could help for speed.

Update: a comparison between TCP and SCTP shows that the performances are comparable unless two interfaces can be used.

Update: a nice introductory article.

philippe
That's good, I'm more interested in things that can be built on top of UDP rather than built on top of IP but it's certainly something that fits in the solution space.
Len Holgate
Thanks for the update and comparison!
Len Holgate
SCTP has many great features (such as multihoming) and with the partial reliability extension (RFC 3758) it's an incredibly flexible option. It's included in the latest linux kernel versions, but for windows you'll have to install your own SCTP stack.
Andrew Johnson
SCTP can be tunneled over UDP. http://tools.ietf.org/id/draft-ietf-sigtran-sctptunnel-00.txt
Miles
Thanks Miles, that's a useful link!
Len Holgate
+3  A: 

If you have a situation where a TCP connection is potentially too slow and a UDP 'connection' is potentially too unreliable what do you use? There are various standard reliable UDP protocols out there, what experiences do you have with them?

The key word in your sentence is 'potentially'. I think you really need to prove to yourself that TCP is, in fact, too slow for your needs if you need reliability in your protocol.

If you want to get reliability out of UDP then you're basically going to be re-implementing some of TCP's features on top of UDP which will probably make things slower than just using TCP in the first place.

17 of 26
Yes, Andrew Edgecombe said as much, but, as I said, I'm interested in the pros and cons of WHAT alternatives there are. Without that list of alternatives and their pros and cons then it's hard to decide what's best.
Len Holgate
Given a known reliablity function, sometimes a UDP stream can be hand-tuned to outrace the TCP stream in hte OS. Rare though.
Joshua
A: 

Did you consider compressing your data ?

As stated above, we lack information about the exact nature of your problem, but compressing the data to transport them could help.

philippe
+5  A: 

As others have pointed out, your question is very general, and whether or not something is 'faster' than TCP depends a lot on the type of application.

TCP is generally as fast as it gets for reliable streaming of data from one host to another. However, if your application does a lot of small bursts of traffic and waiting for responses, UDP may be more appropriate to minimize latency.

There is an easy middle ground. Nagle's algorithm is the part of TCP that helps ensure that the sender doesn't overwhelm the receiver of a large stream of data, resulting in congestion and packet loss.

If you need the reliable, in-order delivery of TCP, and also the fast response of UDP, and don't need to worry about congestion from sending large streams of data, you can disable Nagle's algorithm:

int opt = -1;
if (setsockopt(sock_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, sizeof(opt)))
  printf("Error disabling Nagle's algorithm.\n");
smo
As I said, assuming TCP is at one end of the scale and UDP at the other, what else is there.
Len Holgate
If you want to be pedantic, most of the discussed protocols are built on top of UDP.
smo
The assumption that TCP is at one end and UDP is at the other end is false. e.g. UDP has no flow control, you can easily send packets too fast, causing a router inbetween to drop all of them. Then what do you do ? Ignore the lost packets or resend them ? Resending them and you'll end up reimplementing TCP more or less.Another option for reliable communication is SCTP.
nos
+2  A: 

RUDP - Reliable User Datagram Protocol

This provides:

  • Acknowledgment of received packets
  • Windowing and congestion control
  • Retransmission of lost packets
  • Overbuffering (Faster than real-time streaming)

It seems slightly more configurable with regards to keep alives then ENet but it doesn't give you as many options (i.e. all data is reliable and sequenced not just the bits that you decide should be). It looks fairly straight forward to implement.

Len Holgate
+1  A: 

We have some defense industry customers that use UDT (UDP-based Data Transfer) (see http://udt.sourceforge.net/) and are very happy with it. I see that is has a friendly BSD license as well.

Chris Markle
+1  A: 

May be RFC 5405, "Unicast UDP Usage Guidelines for Application Designers" will be useful for you.

bortzmeyer
+1  A: 

Protocol DCCP, standardized in RFC 4340, "Datagram Congestion Control Protocol" may be what you are looking for.

It seems implemented in Linux.

bortzmeyer