What is slow start?
- Slow start is a method of controlling the capacity of a network connection.
- It restricts how much data may be initially transmitted over a connection, then increases that capacity methodically.
- Slow start is part of the transmission control protocol (TCP).
The capacity of a transfer between a web server and a browser is very small initially and then increases over time.
How a file is transferred
We think of file transfer as one thing...
But in reality it is a collection of transfers of small bits of data...
Each file transfer is in reality many different smaller transfers of data that collectively result in one file being transferred.
A file that is sent across the internet is sent in data packets. Depending on how large the file is, the transfer may take several of these data packets to complete.
Slow start manages the capacity of a transfer
When a TCP connection is initially made, it is only trusted with a small amount of data. If that data transfer went well, it allows more data to be transferred on the next trip.
The amount of data that can be transferred each trip gradually increases.
The reasoning behind this would be basically...
"Why send a whole bunch of data using a connection we aren't sure that works?"
I currently live in the Philippines, and the first time I transferred money from my American bank account to my Philippines bank account, I only transferred 50 dollars. Once I saw that it worked successfully, I made larger transfers because I was confident the system worked and I would get my money.
This is the same theory of slow start which is to make sure the system works prior to increasing the amount of data transferred.
How to lessen the effect of slow start for faster pageloads
We basically just need to understand two things:
- A connection has a tiny capacity at first.
- A connection has a large capacity once it is trusted.
Applying the knowledge of these two simple facts to how we arrange our webpage resources allows us to have faster loading web pages.
Let's look at a few specific examples...
Keep-alive
The longer we keep a connection alive, the more data can be transferred over that connection. Therefore, it is almost always appropriate to enable keep-alive. Ensuring we have a persistent connection will mean more files more quickly.
Since each new connection required for page resources will incur the slow start restrictions, try to use just one connection if possible.
Serve critical files from the same domain
Each domain used requires new DNS lookups, connections, and of course new slow start restrictions.
If we serve critical files from one connection, slow start will not have as much of an overall affect.
HTML file size should be small
The first step a web browser takes to display a page is retrieving the file which contains the HTML.
The size of the HTML file will determine how many trips are needed to transfer it.
Slow start restricts the amount of data that can be transferred each trip keeping the first transfer of data to around 10kb-14kb.
This means that ideally our HTML file should be small enough to be sent in one trip (Less than 10-14kb).
The actual amount of data that can be transferred in a data packet depends on several factors, as does the download time. The important thing is simply the realization that the first thing sent across the connection should be very small in order to use a few trips as possible, because each trip is costly.
Unlike future trips, the very first trip can only contain a small amount of data. If the HTML file can be sent in total during the one trip, your connection is now ready to retrieve larger files in less trips (illustrated below).
Loading page resources
The benefit of sending the HTML within one trip can be better understood by looking at the larger picture of a page loading.
Let's look at a page that has one HTML file and one CSS file and one Javascript file.
In a simplified example the page would load the HTML first, then the CSS, then the JS.
Best case scenario
The best case scenario would be if each of those files could transfer in one trip each. It would look something like this...
In this simplified example, the browser has everything it needs to display the page in 100 ms.
Worse case scenario
Now let's see what happens in an unfortunately more common scenario...
In this scenario, each file takes several trips to take place and keep-alive is not enabled. Notice the affect it has on what the browser is doing and the overall time it takes to get the resources.
Not only do things take longer to download, but also the browser is not doing anything for the vast majority of time.
Delays like this will occur no matter how fast the internet connection is.
If you think the above scenario bad, remember that it is just one css file and one js file. Your webpages likely are loading dozens of such files every page load.
This means that better TCP slow start planning could cave you a great amount of time.