Why Would TCP Increase Speed?


yottabit

Recommended Posts

Someone please help me understand. Why would TCP increase speed with slow CPUs?

TCP packets are larger, and require stateful connection tracking, and retransmissions in the case of corruption.

UDP packets are smaller, stateless, and there are no retransmissions at that layer (4--error detection and retransmission requests must be handled at a higher layer, by the application itself).

In the Internet world, UDP is always faster (on a reliable network), and I don't understand how it would possibly be a higher strain on the CPU except that the application may have to do more error checking since layer-4 isn't handling that for the transmission (but the application would want to do this anyhow, even for TCP, for best reliability and resilience--those properties for which the BT protocol is famously known).

The uTP protocol is based on UDP for the very reason that UDP is less overhead and therefore faster.

Most network interface hardware these days can offload the TCP checksums, but that's a relatively minor operation on today's (and even yesterday's!) CPUs. UDP doesn't even have these checksums.

What about BTSync specifically would make TCP cause a lower load on the CPU?

Link to post
Share on other sites

Well, I've done some digging:

TCP has a congestion control mechanism that throttles the sender when one or more links between sender and receiver becomes excessively congested. This throttling can have a severe impact on real-time applications, which can tolerate some packet loss but require a minimum send rate. On the other hand, the speed at which UDP sends data is only constrained by the rate at which the application generates data, the capabilities of the source (CPU, clock rate, etc.) and the access bandwidth to the Internet.

Source: What are the advantages of UDP over TCP?

So from what I understand - and I'm certainly not an expert in this area - essentially the whole TCP stack runs on-board the network card itself and therefore has a much lower impact on CPU usage than UDP?

In reality then, opting for TCP over UDP in BitTorrent Sync would probably only yield a small speed increase on low-end devices - if you've got a modern, fast, multi-core CPU device, I doubt you'd see much noticeable difference in speed between the two protocols.

Link to post
Share on other sites

There are only a few parts of the TCP protocol that are offloaded to the network PHY. Usually the checksum, and there's one other thing less often that I can't remember right now. Most of TCP is still processed by the network stack (OS/CPU).

I really am surprised by the claim in the FAQ. By all accounts UDP is a leaner, meaner, faster protocol both in terms of smaller header and faster CPU processing. I haven't checked the protocol specifics in a very long time, so I'm not certain whether or not UDP even has a checksum. If it does, perhaps its checksum function isn't typically offloaded to the network PHY whereas TCP's is. Even assuming that's the case, it's still hard for me to see that TCP is faster.

And on a LAN where you have very high transmission speeds and very low probability of errors/collisions, UDP seems like it would really be the shining winner.

If I get some time I'll do some speed tests. I have quite a few SSDs around and a very large RAID-Z2 array. The whole network is gigabit speed, too. I should be able to get a rough comparison.

Link to post
Share on other sites

TCP is well optimized for each OS. There are a lot of kernel optimized things that is happening inside kernel. While UDP is simpler from OS perspective, Sync has to do a lot of uTP activity at user level. This will involve context switching, data copy from kernel to OS etc. This will add overhead especially on low end CPU like NAS.

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.