How TCP Fast Open Can Help Your App
Guest post by Jennifer Leong, Senior Product Development Engineer
TCP (a.k.a., Transmission Control Protocol) is an integral part of how the web works. HTTP runs on top of TCP for most normal usage such as web browsers and web views, so if your app uses HTTP, chances are you’re using TCP, too. Let’s take a look at one way TCP can either help or hurt your application’s performance.
TCP is a self-regulating protocol that aims to provide reliable transmission across IP (also known as Internet Protocol). It is used under HTTP to ensure reliable data transmission. TCP establishes a connection via a three-way handshake, which is meant to prevent denial of service attacks. A three-way handshake consists of the requester sending a “SYN” signal, the server sending an “SYN-ACK,” and then the requester replying with a “ACK.”
One of the ways in which TCP tries to keep transmission reliable is by employing congestion control mechanisms. In order to prevent overloading on a network connection, TCP will start transmitting with a very small window, increasing the window size exponentially until it encounters dropped packets, at which point TCP will cut back the amount of data it sends.
TCP Performance Issues and TCP Fast Open (TFO)
The three-way handshake introduces round trip time (RTT) delay. How does this compare to user-tolerable delay?
The lag time due to three-way handshake is equal to 1.5 times the round-trip time. That’s just to set up the connection and make a request (which can be sent with the last ACK). It then takes another trip to start returning usable data, making the total latency 2x RTT!
Since typical RTTs for a mobile connection are often upwards of 200ms, this means that a substantial portion of the 2-second window within which users expect to see content is tied up in just establishing a TCP connection. It might seem like a miracle is needed to get to the 1-second load time that will boost your search engine rank.
One mitigation? TCP Fast Open (TFO), where a server sets a cookie on the requester, which allows it to reply with data in the initial SYN request that the server can process immediately, cutting down on one RTT. In original TCP, the requester can send data in the original SYN request, but the server is required to hold off processing that request data until the connection is fully established. The TFO cookie tells the server that it has successfully established a connection with this requester before, so it’s trustworthy enough to accept data with the first SYN rather than waiting for the ACK.
TCP Fast Open has been available since Linux 3.7, so upgrade, or turn it on! Versions of Linux 3.13 and up ship with it already turned on. For more details on TCP Fast Open and how to turn it on for versions 3.7-3.13, click here.
For additional tips on speeding up your mobile apps and websites, check out the ARO Best Practices.