Search code examples
http2multiplexing

Does http2 include a demux mechanism?


As I simply understands HTTP2 is m:1 pattern where you put m logical connections into 1 TCP stream

Is it possible to do m:n pattern in http2?

m streams are demuxed into n connections for better reliability, because often one single TCP breaks all h2 hangs.


Solution

  • It would be possible, but in practice it is not done.

    Browsers especially try hard to open just one connection to a domain, and even reuse the same connection for different subdomains if they can figure out that it resolves to the same IP address and same certificate.

    Other clients may implement a m:n scheme (for example, Jetty 9.4.x HTTP/2 client does - disclaimer: I'm the maintainer).

    The problem of choosing a good n may not be trivial, and it risks to go back to HTTP/1.1 6-8 TCP connections per domain.

    Since each connection would be multiplexed anyway, the failure of a single HTTP/2 connection would be worse than the failure of a single HTTP/1.1 connection (because it would fail multiple requests rather than just one), so I guess that it would not make that much of a difference with respect to a single HTTP/2 connection.

    Google's QUIC protocol aims at resolving this issue since it is based on UDP and has built-in in support for connection migration (i.e. switching from WiFi to mobile network).