I was playing around on WebSiteTest today â€“ trying out it new IE9 test feature, and I noticed something new that IE9 does: preconnect.
What is preconnect? Preconnect is making a connection to a site before you have a request to use that connection for. The browser may have an inkling that it will need the connection, but if you donâ€™t have a request in hand yet, it is a speculative request, and therefore a preconnect.
IE9 isnâ€™t the first to use preconnect, of course. Chrome has been doing preconnect since ~Chrome7. So it is nice to see other browsers validating our work. But, IE9 is the first browser I know of which appears to preconnect right out of the gate, without any data about a site. Chrome, on the other hand, will only preconnect based on data it has learned by observing network activity through repeat visits to a site. As such, Chrome usually is issuing the same number of connects and network traffic, just with less delay.
Here is the trace where I first noticed this behavior on WebPageTest. Notice that WebPageTest did not record any connect-time delay on the second request to dev.chromium.org. How can this be? Because the socket was already connected.
To understand this better, I then opened up WireShark and watched the packets. The packet trace clearly shows that IE9 simply opens 2 connections, back to back, for every domain the browser connects to. This isnâ€™t a horrible assumption for the browser to make â€“ since many sites will indeed require more than one connection per domain already.
But it also wasnâ€™t hard to notice cases where it connects wastefully. On belshe.com, for instance, there is a single link to a YouTube video requiring only one resource. IE9 opens two connections to YouTube anyway (WebPageTest doesnâ€™t show the unused connection in its trace, by the way, but it is in the trace!). One connection loads the image, the other connection is wasted. YouTube diligently kept that connection open for 4 minutes too! There are also a couple of 408 error responses from Akamai – it appears that the Akamai server will send a graceful 408 error response to an empty connection after some period of time.
But is this a problem?
As long as the level of accidental connects is minimal, probably not. And much of the time, 2 connections are useful. It would be great to hear from the IE9 team about their exact algorithm and to see if they have data as to how much extra resources they are using?
WebPageTest already offers some clues. For belshe.com, for example, I can see that IE8 uses 20 connections, while IE9 is now using 23 connections to render the page. 10% overhead is probably not the end of the world.
What about SSL?
I love SSL, so of course this got me wondering about what IE9 does for preconnecting https sites too. Sure enough, IE9 happily preconnects SSL too. [Sadly â€“ it even forces the server to do two full SSL handshakes- wastefully generating 2 session-ids. This is a bit more annoying, because that means the main site was just put through double the number of PKI operations. Fortunately, PKI operations are relatively cheap these days. Iâ€™d complain more, but, tragically, Chrome is not much better yet. Did I mention that SSL is the unoptimized frontier?]
Brian Boitano Chrome Do?
As I mentioned, Chrome has been doing preconnect for some time. But, Chrome doesnâ€™t preconnect right out of the gate. We were so worried about this over-connecting business that we added gloms of
more complicated code highly sophisticated, artificial intelligence before turning it on at all 🙂
Specifically, Chrome learns the network topology as you use it. It learns that when you connect to www.cnn.com, you need 33 resources from i2.cdn.turner.com, 71 resources from i.cdn.turner.com, 5 resources from s0.2mdn.net, etc etc. Over time, if these patterns remain true, Chrome will use that data to initiate connections as soon as you start a page load. Because it is based on data, we hope and expect that it will much less often connect incorrectly. In fact, it should be making the same number of connections, just a little earlier than it otherwise would. But all of this is an area that is under active research and development. (By the way, if you want to see how Chrome works, check out the ultra-chic-but-uber-geek â€œabout:dnsâ€ page in your Chrome browser)
So does all this fancy stuff make my Internet faster?
Fortunately, we have pretty good evidence that it does. Weâ€™re monitoring this all the time, and Iâ€™d say this work is still in its infancy. But here is some data from Chromeâ€™s testing in 2010.
Our Chrome networking test lab has a fleet of client machines (running Linux), a simulated network using dummynet (see Web-Page-Replay for more information), and some fast, in-memory servers. We record content from the top-35 websites, and can play it back repeatedly with high fidelity. Then we can change the network configuration and browser configuration and see how it all works out.
In my test, I picked 4 different network configurations. I then varied the RTT on each connection from 0 to 200ms.
Here is a graph of page load time (PLT) improvements in this test.
Overall, weâ€™re pretty happy with this result. When the RTT is zero, preconnect doesnâ€™t really help, because the connections are basically free (from a latency perspective). But for connections with RTTs greater than ~50ms, we see a solid 7-9% improvement across the board. (typical RTTs are 80-120ms)
The Larger Question
While this is great for performance now, I am worried about the wastefulness of HTTP on the Internet. We used to only have one domain per site, now we have 7. We used to have only 2 connections per domain, but now we have 6. And on top of that, now weâ€™re preconnecting when we donâ€™t even need to?
With itâ€™s proliferation of TCP connections, HTTP has been systematically sidestepping all of TCPâ€™s slow start and congestion controls. Sooner or later will the internet break? Throwing inefficiency at the problem canâ€™t go on forever.
So one last note â€“ a blatant plug for SPDY
The downside of preconnect is a big part of why weâ€™re working on SPDY. HTTP has been nothing short of a heroic protocol and made the Internet as we know it possible. But as we look to the next generation of rich media sites with low latencies, it is clear that todayâ€™s HTTP canâ€™t perform at that level.
SPDY hopes to solve much of HTTPâ€™s connection problems while also providing better performance and better security.
With that, I guess I need to get back to workâ€¦
7 thoughts on “The Era of Browser Preconnect”
Pingback:Tweets that mention Mike's Lookout Â» Blog Archive Â» The Era of Browser Preconnect -- Topsy.com
Pingback:IE9 Preconnect | Joseph Scott
Interesting article. Are there browsers other than IE9 and Chrome using this? Are there extensions that add this functionality to browsers that don’t have it built in?
FYI, you can also get a wireshark directly from WebPagetest (tcpdump checkbox in the advanced settings). That way you can get the raw network trace that corresponds to the test data.
Thanks Mike for the deep insight, I believe your referring to Chrome’s “Web Page Prerendering.” experimental feature. I was afraid of enabling it because of the reasons you have provided that IE9 is doing. But since there is artificial intelligence when it prerenders, it makes me want to enable it now!
SPDY is promising, you guys are doing a wonderful job 🙂
> Sooner or later will the internet break?
That adding more TCP connections helps performance so much is I think an indication that the Internet can absorb more data immediately after connection setup than we are taking advantage of.
There is a proposal in IETF now to increase the initial congestion window for TCP from 3 segments to 10, for exactly that reason: the bulk of the Internet is able to handle more.
Pingback:22 not-so-short links about web performance — Web Performance Today