Why is HTTP / 2 multiplexing better than http / 1.1?

advertisements

In HTTP/1.1 Case, a web page has multiple resouces, per file will create a connection to server side to retrieve data, js, css, etc. I think the mode of work is similar to mutli-process or multi-thread, work in parallel.

But in HTTP/2 Case, per domain only has one connection in a web page, even if it can handle mutliple request from client's browser, maybe it is similar to single thread.

I don't know the reason why the performance is better in http/2 than in http/1.1 ?


The reason HTTP/2 multiplexing is more efficient than HTTP/1.1 for web pages has very little to do with the cost of opening TCP connections.

In HTTP/1.1, browsers open typically at most 6 connections per domain. After those connections are open, they are kept open and reused over and over, until they go idle.

Yet, HTTP/2 is faster than HTTP/1.1 even after those connections have been opened, so it is clearly not the cost of TCP connection opening in play here.

A typical web page today may have up to 100 resources to be downloaded from the origin server. Let's keep things simple and imagine there is a 200 ms roundtrip between client and server. In order to download the page in HTTP/1.1, the browser has to download the main HTML page (1 roundtrip), then parse the HTML page and arrange to download the 100 resources - but it only has 6 connections. So the browser sends the first 6 requests, then waits for them to come back (1 roundtrip); then another 6 requests, then waits for them to come back (1 roundtrip); etc. In this simple model, to download 100 resources the browser needs 1 + 17 roundtrips, at 200 ms each it means 3.6 seconds.

In HTTP/2, the browser makes the request for the HTML page, but then it is free to make all the requests for the 100 resources without waiting, thanks to the fact that HTTP/2 is multiplexed. In this simple model, to download 100 resources the browser needs 1 + 1 roundtrips, that is 400 ms, for a 10x speedup in download time.

Now, things are not as simple as depicted above, but still the gain due to multiplexing has quite an impact.

You can look at this impact yourself by watching examples online (here and here), and you can watch my HTTP/2 presentation on this and other HTTP/2 benefits (you can watch the demo that explains the multiplexing effect here).