Block Details Banner Image
Vector IconSvg

Understanding TCP Throughput: Basics, Calculations, and Optimization Techniques

Author Image
Tutorials
Welcome to our Foundations Series, where we revisit the timeless fundamentals that power modern cloud computing. At Genesis Cloud, we’re pushing the boundaries of AI and high-performance computing with cutting-edge GPU solutions. However, every innovation rests on a foundation of core principles.

This article kicks off the Networking and Optimization Series, a sub-series within the Foundations Series, focusing on essential protocols and techniques that ensure seamless data transmission and network performance. Our journey begins with TCP, the backbone of reliable communication, where we’ll explore its fundamentals, throughput calculation, and optimization techniques for modern cloud environments.

What is TCP and why does it matter for reliable data transmission?

TCP, or Transmission Control Protocol, is extensively utilized for ensuring dependable data transmission across the Internet. This protocol governs the connection between two devices engaged in data exchange and oversees the division of application data into packets. Moreover, TCP is responsible for sending and receiving packets while managing their flow. Additionally, it addresses dropped packets by retransmitting them and verifies the status of received packets.

TCP has three key features that are essential to understand:

  1. Connection-oriented: TCP creates a connection between two specific servers.
  2. Reliable: TCP ensures the delivery of segments, regardless of network conditions.
  3. Bitstream-oriented: In TCP, application layer data is segmented and the transport layer does not consider message boundaries. Segments must be processed in order, and any duplicate segments are discarded.

Nevertheless, TCP was initially developed for conventional networks and may not be well-suited for cloud environments. In the cloud, factors such as latency, bandwidth, congestion, and packet loss can fluctuate significantly. As a result, applications and services operating in the cloud might require the implementation of TCP optimization methods to improve their performance, scalability, and user experience.

Understanding TCP throughput: Definition, importance, and factors

Throughput is commonly quantified by the volume of data transmitted per unit of time, such as bits or bytes per second. Achieving a higher throughput entails sending a greater amount of data in a shorter duration. TCP incorporates flow control and windowing mechanisms, leading to variations in TCP throughput over the course of data transmission. Let's delve into the process of calculating TCP throughput between a client and a server.

Link speed from client to server

For instance, as depicted in the figure above, there exists a client and a server with a link speed of 100Mbps. The round-trip time between the client and server is 40ms. Despite the availability of 100Mbps bandwidth on the link, the client experiences slow download speeds while attempting to retrieve files from the server. Consequently, it will still require time to complete file downloads.

Client sends TCP with windows side

It may be beneficial to conduct a packet capture between the client and server in order to gain further insight into the current throughput of this transfer. The capture can be executed on either the client or intermediate nodes. The primary objective of the packet capture is to determine the TCP window that the client transmits to the server. For instance, we have observed that the TCP window sent by the client to the server is 65000 bytes, as illustrated in the figure above. It's important to note that TCP window size is always expressed in bytes. You can refer to TCP header for a detailed understanding of TCP fields.

How to calculate TCP throughput: A step-by-step example

TCP throughput(bps) = Window Size(bits) / RTT (sec)

TCP throughput: Speed calculated in bits per second.

Window Size: As bits in bps. Convert the window bytes to bits i.e. multiply by 8.

RTT: Round trip time measured in milliseconds. Covert to second i.e. divide by 1000. Finally, let’s add the figures discussed in this formula to get the TCP throughput

Window Size in bits: 65000*8 = 520000 bits

RTT in seconds: 40/1000 = 0.04

520000/0.04 = 13000000 bps which is 13Mbps

Therefore, based on the calculation above, we can determine that with a window size of 65000 bytes and an RTT of 40ms, the throughput is approximately 13Mbps. This value is significantly lower than the capacity of the link. Despite the server's ability to transmit more data over the network, the reduced window size communicated by the client has led to fewer bytes in transit, consequently slowing down the download speed. To address this issue and enhance TCP throughput, it may be necessary to make adjustments to the TCP window size on the client side.

Top TCP optimization techniques for better network performance

Based on the explanation of TCP throughput above. We can see there are so many techniques to optimize TCP throughput.

Tuning

The process involves adjusting the parameters and settings of TCP to align with the characteristics and demands of the cloud network. To enhance the throughput, latency, and reliability of TCP connections, we can fine-tune the following parameters:

  • TCP Window Scaling enables us to expand the window size beyond the default limit, facilitating larger data transfers and reducing the number of necessary acknowledgments. As a result, it enhances overall throughput.
  • Selective Acknowledgment (SACK) is a valuable mechanism that empowers the receiver to notify the sender about any missing or out-of-order packets. This capability facilitates quicker retransmission and helps in minimizing unnecessary retransmissions.
  • TCP Fast Open (TFO): TFO allows clients to transmit data in the first SYN packet, which helps minimize the time taken for connection establishment. This enhancement is especially advantageous for connections that are short-lived.
  • Path Maximum Transmission Unit Discovery (PMTUD): PMTUD helps optimize TCP performance by determining a network PMTUD size. By avoiding fragmentation, PMTUD reduces the chances of packet loss and improves overall efficiency.
  • TCP Congestion Control Algorithms: TCP employs various congestion control algorithms, such as TCP Cubic, Reno, and BBR. These algorithms determine how TCP reacts to network congestion. Choosing the appropriate algorithm for specific network conditions can significantly enhance performance.

Offloading

This process involves transferring TCP processing tasks from the application server to a specialized device, like a network interface controller (NIC), load balancer, or proxy server. This can be highly beneficial as it helps to alleviate resource constraints on the system and enables it to manage additional connections.

  • The TCP checksum offload option allows the network adapter to calculate the TCP checksum during transmission and reception, reducing the need for the host CPU to perform this calculation. The amount of savings achieved with this option depends on the size of the packets being processed. Small packets may not yield significant savings, whereas larger packets can result in more noticeable reductions in CPU usage.
  • Segmentation Offload: When enabled, a network internet controller (NIC) divides large data chunks traveling over a network into smaller TCP segments.
  • TCP Chimney Offload, also known as TCP offloading, is a feature that allows the network interface card (NIC) to take over the processing of established TCP connections. This can help improve network performance and reduce CPU usage on the host system.

Splitting

This technique aims to decrease latencies and address TCP issues by dividing a connection that would result in a high round-trip time into smaller segments. Split TCP allows the client's TCP connection to end within a server’s proximity to the user, while a distinct TCP connection is set up to the origin, potentially having a significant round-trip time (RTT). The diagram below depicts how three users from various geographical locations connect to a server close to their respective locations. Subsequently, the server maintains an enduring connection with the origin in Europe.

Establishing a TCP connection involves 3-5 roundtrips from the client to the server. The architecture of the server plays a crucial role in optimizing this process. By minimizing the number of round trips, "short connections" between end users and servers reduce latency, resulting in improved performance. On the other hand, "long connections" between servers and origins can be pre-established and reused for multiple user requests to enhance connectivity efficiency. Notably, when setting up an SSL/TLS (Transport Layer Security) connection, Split TCP's impact is amplified due to additional round trips required for securing the connection.

Alternating

These protocols are designed to enhance performance and functionality compared to TCP for specific cloud scenarios and applications. Consider the case of an eCommerce website as an example.

  • DNS (Domain Name Service): When a URL (Uniform Resource Locator) is entered into a web browser, a DNS resolver translates the hostname of the URL to an IP address. This process enables us to locate web resources effectively. The DNS resolver interacts with a hierarchy of name servers in order to retrieve this mapping.
  • HTTP/HTTPS: The website's REST API facilitates user interaction by utilizing HTTP to handle request methods. When a user chooses to buy a car, the website generates an order.
  • Binary protocol over TCP: The order service communicates with the payment service to initiate a payment transaction. In a microservice architecture, this interaction typically occurs through a Kafka message queue, which utilizes a binary protocol over TCP. The protocol outlines all APIs as pairs of request and response messages. Each message is delimited by size and consists of primitive types. The client establishes a socket connection, sends a series of request messages, and receives corresponding response messages without requiring any handshake for connection or disconnection.
  • WebSocket: The establishment of a WebSocket by client-side applications with the backend enables full-duplex communication over a single TCP connection. This allows client-side applications to receive push notifications, such as notifying the user's device about the success of a payment transaction.
  • SMTP: The email notification service functions by sending an official email to the user's designated email address through the use of SMTP (Simple Mail Transfer Protocol).
  • Ping (ICMP): An engineer observes a decrease in the efficiency of the services and employs the ping command to assess the server's accessibility.
  • Video call (UDP): Next, the team of engineers should engage in a discussion to explore potential solutions. They can convene for a video call using an application such as Google Meets, which operates on UDP rather than TCP.

Testing

This approach involves assessing the functionality, performance, and reliability of TCP in a network environment. It includes simulating various scenarios to evaluate TCP connection behavior and measure parameters such as throughput, latency, and packet loss. Conducting TCP tests can help identify issues, optimize settings, and ensure reliable and efficient connections for smooth communication and data transfer. By using tools like synthetic monitoring or methods to test latency, bandwidth, throughput, packet loss, jitter, and retransmission rate of TCP connections we can enhance network performance and validate implementations across devices and platforms.:

  • Ping: Once the network software has been configured and the IP addresses have been set, it's important to use the ping command on the sharing node to verify that all of the nodes are operational.
  • Telnet: This tool was traditionally used for testing the connectivity of TCP ports, but it has been widely replaced by nc (Netcat), which offers more flexibility and supports both TCP and UDP.
  • Tcpdump: This tool is known as a packet analyzer, and it is typically initiated from the command line. It serves the purpose of examining network traffic by capturing and presenting packets that are either generated or received by the host computer. This software operates on Linux and various UNIX-based operating systems.
  • iperf3: This program is a free open-source, cross-platform command-line-based tool designed for conducting real-time network throughput measurements. It stands out as one of the most powerful tools available for testing the maximum achievable bandwidth in IP networks and supports both IPv4 and IPv6..

These tools enable us to monitor the establishment of low-level TCP connections on specific ports of designated hosts. This ensures the availability of important services like SSH (22), HTTP (80), HTTPS (443), and any custom microservices operating on other ports.

In summary, conducting TCP testing can assist in pinpointing and understanding the underlying issues related to TCP, as well as confirming and validating the impacts of TCP optimization methods. Understanding TCP is just the beginning. Reliable communication across the Internet also relies on protocols like the Domain Name System (DNS), which acts as the Internet’s address book. In our next article, part of the Networking and Optimization Series, we’ll explore how DNS resolves domain names into IP addresses, its role in cloud performance, and tips to optimize it for modern environments.

Keep accelerating

The Genesis Cloud team 🚀

Never miss out again on Genesis Cloud news and our special deals: follow us on Twitter, LinkedIn, or Reddit. Sign up for an account with Genesis Cloud here.

If you want to find out more, please write to contact@genesiscloud.com.

Checkout our latest articles