Ryan Peschel
Ryan Peschel

Reputation: 11828

Is there still a practical 6 connection limit when using Server Sent Events with HTTP2?

I've been googling around and I cannot seem to find a straight answer to this question, and some people offer contradictory answers.

Most browsers have a 6 connection limit for each domain. So for example, if your website is example.com and it initializes a persistent Server Sent Event connection on page load, then the end user can open that tab five more times, but the sixth tab won't load at all, because the 6 persistent TCP connection has been reached for that domain.

Now, I see some people saying that this is just a perennial problem with SSE, and the only alternative is hacky workarounds involving detecting this connection limit and then either closing the connections in hidden tabs or closing those connections in those tabs and switching to long polling.

However, some people claim that HTTP2 solves this with multiplexing, such that you can have as many open tabs of that website as you'd like, as all the tabs multiplex onto the same TCP connection. I cannot find a primary source for this claim, nor anyone with significant authority making it either.

So, is it true? Does HTTP2 multiplexing solve the issue of the common 6 connection limit for website domains? Or is one basically required to instead use websockets if they would like to support many open tabs to their site?

Upvotes: 8

Views: 6060

Answers (2)

Darren Cook
Darren Cook

Reputation: 28968

The limit is applied in the browser (not server-side), and varies per browser.

At least it did as of http/1.1. I've been unable to find any configuration specific to http/2, so I think we have to assume the limits are still there. I would assume they've been kept to prevent abuse, or accidental DoS attacks.

https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Mozilla_networking_preferences

See network.http.max-persistent-connections-per-server. (You can also see it in about:config.)

Here are all the settings I see (in Firefox) filtering for "connections":

enter image description here

I wonder if SSE is governed by http.max-connections or the websocket.max-connections? (Ignoring any per-domain limit, for the moment.)

You could also just try it, of course (there were example scripts in my above-linked question). But unless you control the configuration of all clients, you have to assume some people will be running with a limit of 6.

Upvotes: 0

sbordet
sbordet

Reputation: 18617

I have implemented HTTP/2 in Jetty.

As explained in this answer, with HTTP/2 the max number of concurrent requests that a browser can make to the server is largely increased - not infinite but increased from 6-8 to about 100.

So yes, multiplexing solves this issue in practice (unless you open more than 100 or so tabs).

Note that this value is configured by servers, so it's possible that a server sends to the client a configuration with max number of concurrent requests set to a small number, but in practice servers have settled on a number around 100.

Having said that, you want to also read this other answer for a discussion about SSE vs WebSocket.

Upvotes: 7

Related Questions