- Check pconn pool for idle http connection
- if that succeeds, dispatch
- if limits allow, open a tcp connection and when that completes dispatch on it
- otherwise queue it and goto 1 when an existing transaction completes
- Check pconn pool for idle http connection
- if that succeeds, dispatch
- queue transaction
- if limits allow, start a tcp connection which will be added to the pconn pool when it completes
- whenever a pconn is available or a transaction completes check queue for dispatch
It turns out this happens, anecdotally, a whole freaking lot. My test network has a delay of about 250ms between Firefox and each server.
Loading the NY Times required 219 TCP connections of which 141 (64%) were able to be served on a different persistent connection that became available between the time we started to open the connection and the time the handshake actually completed.
Loading the wall of one of my facebook pals saw this behavior on 9 of 27 connections (33%), and the cnn home page performed similarly to NYT - 76/117 (65%).
This makes some intuitive sense - if you have a piece of HTML that includes an img it is entirely likely that we will start the request for the img before we have finished transferring the HTML, but the HTML will finish transferring before the new handshake (which will take a full RTT) completes. This algorithm just moves the request for the img over to the HTML persistent connection which can proceed as soon as the HTML is done.
The amount of latency saved is variable - indeed it is probably at least somewhat uniformly random with 0 and RTT as its bounds. I was seeing a mean of around 80ms on each one. Of course this doesn't apply to all transactions - just ones that are opening TCP connections to servers that also do persistent connections.
but its still cool.