Yesterday I started to write about network performance. When talking about the Internet, we can’t forget the protocols which are the driving force of the Internet. We can divide the entire architecture in to few layers and study it by layers. According to the TCP architecture, there are 5 layers in a network,
- Application Layer
- Transport Layer – TCP/UDP
- Network Layer – IP
- Data Link Layer
- Physical Layer
Here I have mentioned the protocols in the transport layer and the network layer as well. So let’s talk about TCP and UDP from this text as Transport Layer Protocols.
Transmission Control Protocol or TCP is the main protocol used these days in the Transport Layer. We can take IP with TCP and then it is known as TCP/IP. Let’s see some of the characteristics of the TCP protocol,
- Connection oriented.
- Reliable data transmission.
- Error handling.
- Not the fastest.
- Retransmission of lost data.
- In-order delivery.
- Congestion control and avoidance.
- Data integrity.
- Preserve the order of delivery.
- Use three way handshaking.
Because of these characteristics, TCP is good for transmission of data which need a reliability rather than concerning about the speed of the delivery. For example,
- World Wide Web.
- File transfers.
Those are few examples of TCP in real life. When talking about the characteristics of TCP, I mentioned it as a connection oriented protocol and also it uses three way hand shaking. Let’s see what does that mean.
THREE WAY HANDSHAKING
All TCP connections begin with a three-way handshake. Before the client or the server can exchange any application data, they must agree on starting packet sequence numbers, as well as a number of other connection specific variables, from both sides. The sequence numbers are picked randomly from both sides for security reasons. Using this handshaking procedure they will establish a connection between the client and server before sending data. Because of this connection we can say it’s a connection oriented protocol as well as it’s reliable.
- SYN : Client picks a random sequence number x and sends a SYN packet, which may also include additional TCP flags and options.
- SYN ACK : Server increments x by one, picks own random sequence number y , appends its own set of flags and options, and dispatches the response.
- ACK : Client increments both x and y by one and completes the handshake by dispatching the last ACK packet in the handshake.
The time taken for this three way hand shaking procedure makes the TCP more time consuming at the setup. So it’s good to reduce the new setups and reuse the existing once. Also because of this late at the startup, the Latency of TCP is much more greater than the UDP. But after all it provides a reliable data transmission.
As I told earlier, latency is the greatest drawback of the TCP protocol. But we can use some optimizations and make the delay reduce to get the best performance out of the protocol. Let’s see what we can do,
- Increase TCP’s initial congestion window.
- Disable slow start.
- Enable window scaling.
- Allows application data to be sent in the initial SYN packet in certain situations.
- Use the latest kernel.
- No bit is faster than one that is not sent; send fewer bits.
- Compress the transferred data.
- Reuse the TCP connection.
User Datagram Protocol or the UDP is the second protocol which can be used in the Transport Layer as a replacement for the TCP protocol. Let’s see some of the characteristics of the UDP protocol,
- Connection less protocol.
- No reliability in the transmission.
- No error handling.
- Provide the fastest transmission.
- Don’t preserve the order of the delivery.
- No retransmission.
Because of these characteristics, UDP is good for transmission of data which need real time delivery of data without concerning about the reliability of the transmission. For example,
- Media streaming
- Local broadcast mechanisms
Those are few examples of UDP in real life.
Let’s see some of the optimizations which we can used to make our UDP protocol works efficient.
- Application must tolerate a wide range of Internet path conditions.
- Application should control rate of transmission.
- Application should perform congestion control over all traffic.
- Application should use bandwidth similar to TCP.
- Application should back off retransmission counters following loss.
- Application should not send datagrams that exceed path MTU.
- Application should handle datagram loss, duplication, and reordering.
- Application should be robust to delivery delays up to 2 minutes.
- Application should enable IPv4 UDP checksum, and must enable IPv6 checksum.
- Application may use keepalives when needed (minimum interval 15 seconds).
Hope now you have a clear idea about these two transport layer protocols and how to optimize them to get the best performance out of them. See you soon with another important topic. Thank You!