How to calculate the throughput?
There are several ways, depending on what exactly you want to measure. They all come down to dividing a certain number of bits (or bytes) by a certain duration, as you mention; which depends on what bits you count or (less commonly) what time points you are considering for measuring duration.
Factors you should consider:
At what level of network stack do you measure throughput?
If you measure at the application level, all that matters is what useful data you transfer to another endpoint. For example, if you transfer a file of 6 KB in size, the amount of data that you calculate when measuring throughput is 6 KB (i.e. 6,000 bytes, not bits, and pay attention to a factor of 1000, not 1024; these conventions are common in the network )
This is usually called goodput and may differ from what is actually sent at the transport level (as in TCP or UDP), for two reasons:
1. Heading overhead
Each layer in the network adds a header to the data, which introduces some overhead due to its transmission time. Moreover, the transport layer breaks your data into segments; This is because the network layer (as in IPv4 or IPv6) has a maximum packet size called MTU , usually 1500 V on Ethernet networks. This value includes the size of the network layer header (for example, the IPv4 header, which has a variable length but usually 20 V long) and the transport layer header (for TCP it is also variable in length, but usually 40 V long). This leads to the fact that the maximum size of the MSS segment (the number of bytes of data without headers in one segment) is 1500 - 40 - 20 = 1440 bytes.
Thus, if we want to send 6 KB of application-level data, we must split them into 6 segments, 4 of 1440 bytes each and one of 240 bytes. However, at the network level, we send 6 packets of 4 of 1,500 bytes each and one of 300 bytes, which in total is 6.3 kB.
Here I did not take into account the fact that the data link layer (as in Ethernet ) adds its own header and, possibly, also a suffix, which additionally increases overhead. For Ethernet, this is 14 bytes for the Ethernet header, an additional 4 bytes for the VLAN tag, then a CRC of 4 bytes and a gap of 12 bytes, for a total of 36 bytes per packet.
If you are considering a channel with a fixed speed of, say, 10 Mbps, depending on what you are measuring, you will get a different bandwidth. Usually you want one of them:
- Good performance, that is, application-level bandwidth if you want to measure application performance. In this example, you divide 6 KB by the transmission duration.
- Link layer bandwidth if you want to measure network performance. In this example, you divide 6 kB + TCP overhead + IP overhead + Ethernet overhead = 6.3 kB + 5 * 36 B = 6516 B by the transmission duration.
Relay Costs
The Internet is a network with maximum effort, which means that packets will be delivered, if possible, but can also be dropped. Dropping packets is adjusted by the transport layer, in the case of TCP; for UDP there is no such mechanism, which means that either the application doesnβt care if some pieces of data are being delivered, or the application itself retransmits over UDP.
Retransmission reduces useful performance for two reasons:
a. Some data needs to be sent again, which takes a lot of time. This introduces a delay that is inversely proportional to the speed of the slowest channel in the network between the sender and receiver (it is also a bottleneck). b. Detecting that some data has not been delivered requires feedback from the recipient to the sender. Due to propagation delays (sometimes called delays; caused by the finite speed of light in the cable), feedback can only be received by the sender with some delay, which further slows down the transmission. In most practical cases, this is the most significant contribution to the additional delay caused by retransmission.
It is clear that if you use UDP instead of TCP and do not care about packet loss, you will certainly get better performance. But for many applications, data loss is unacceptable, so this measurement does not make sense.
There are some applications that use UDP for data transfer. One of them is BitTorrent, which can use either TCP or the protocol they developed, called uTP , which emulates TCP over UDP, but aims to increase efficiency when using multiple parallel connections. Another transport protocol implemented over UDP is QUIC , which also emulates TCP and offers multiplexing of multiple parallel transmissions over a single connection and direct error correction to reduce retransmissions.
I will discuss a bit of direct bug fixes a bit as it is related to your bandwidth issue. A naive way to implement this is to send each packet twice; in case one is lost, the other still has a chance to be received. This reduces the number of retransmissions by half, but also halves your useful performance because you send redundant data (note that the bandwidth of the network or link layer remains unchanged!). In some cases, this is normal; especially if the delay is very large, for example, on intercontinental or satellite channels. Moreover, there are some mathematical methods where you do not need to send a full copy of the data; for example, for every n packets that you send, you send another redundant packet, which is XOR (or some other arithmetic operation) of them; if the excess is lost, it does not matter; if one of n packets is lost, you can restore it based on the excess of one and the other n-1. Thus, you can configure the overhead of direct error correction for any amount of bandwidth that you can save.
How do you measure transmission time
Is the transfer complete when the sender has finished sending the last bit over the wire, or does it also include the time it takes for the last bit to reach the receiver? In addition, does it include the time required to receive confirmation from the recipient, which states that all the data was received successfully and that no retransmission is needed?
It really depends on what you want to measure. Please note that for large gears, one extra round-trip time is negligible in most cases (if you do not communicate, for example, with a probe on Mars).
What is this key feature in TCP that allows it to have much higher throughput than UDP?
This is not true, although a common misconception.
In addition to retransmitting data when necessary, TCP will also adjust the sending speed so as not to cause packet drops due to network congestion. The tuning algorithm has been improved over decades and usually quickly converges to the maximum speed supported by the network (actually a bottleneck). For this reason, it is usually difficult to outperform TCP in bandwidth.
With UDP, the sender has no speed limit. UDP allows the application to send as much as it wants. But if you try to send more than the network can process, some data will be discarded, which will reduce your bandwidth, and also make the administrator of the network that you overload very angry. This means that sending UDP traffic at high speed is impractical (unless the goal is a DoS network).
Some multimedia applications use UDP, but limit the transmission speed on the sender at a very low speed. This is typically used in VoIP or Internet radio applications where very low bandwidth but low latency are required. I believe this is one of the reasons for the misconception that UDP is slower than TCP; it is not, UDP can be as fast as the network allows.
As I said before, there are protocols like uTP or QUIC implemented over UDP that achieve performance similar to TCP.
It's true?
TCP throughput = (TCP Window Size / RTT)
Without packet loss (and retransmissions), this is correct.
TCP throughput = BDP / RTT = (Link Speed in Bytes/sec * RTT)/RTT = Link Speed in Bytes/sec
This is only correct if the window size is set to the optimum value. BDP / RTT is the optimal (maximum) transmission rate in the network. Most modern operating systems should be able to automatically configure it.
How does bandwidth depend on block size? Is the block size equal to the size of the TCP or UDP window?
I do not see the block size in the iperf documentation .
If you refer to the size of the TCP window, if it is smaller than BDP, then your throughput will not be optimal (because you spend time waiting for the ACK instead of sending more data; if necessary, I can explain in more detail). If it is equal to or higher than BDP, you will achieve optimal throughput.