3 ms·
the biggest drawback with SSE, even when unidirectional comm is sufficient is > SSE is subject to limitation with regards to the maximum number of open connect
by leeoniya 5y ago
the biggest drawback with SSE, even when unidirectional comm is sufficient is
> SSE is subject to limitation with regards to the maximum number of open connections. This can be especially painful when opening various tabs as the limit is per browser and set to a very low number (6).
https://ably.com/blog/websockets-vs-sse https://ably.com/blog/websockets-vs-sse
SharedWorker could be one way to solve this, but lack of Safari support is a blocker, as usual. https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker https://developer.mozilla.org/en-US/docs/Web/API/SharedWorke...
also, for websockets, there are various libs that handle auto-reconnnects
https://github.com/github/stable-socket https://github.com/github/stable-socket
https://github.com/joewalnes/reconnecting-websocket https://github.com/joewalnes/reconnecting-websocket
https://dev.to/jeroendk/how-to-implement-a-random-exponential-backoff-algorithm-in-javascript-18n6 https://dev.to/jeroendk/how-to-implement-a-random-exponentia...
- bullen 5y agoIt used to be 2 sockets per client, so now it's 6? Well it's a non-problem, if you need more bandwith than one socket in each direction can provide you have much bigger problems than the connection limit; which you can just ignore.
- leeoniya 5y agothe problem is multiple tabs. if you have, e.g. a bunch of Grafana dashboards open on multiple screens in different tabs (on same domain), you will exhaust your HTTP connection limit very quickly with SSE. in most cases this is not a concern, but in some cases it is.
- bullen 5y agoAha, ok yes then you would need to have many subdomains? Or make your own tab system inside one browser tab. I can see why that is a problem for some.
- coder543 5y agoThis isn’t a problem with HTTP/2. You can have as many SSE connections as you want across as many tabs as the user wants to use. Browsers multiplex the streams over a handful of shared HTTP/2 connections. If you’re still using HTTP/1.1, then yes, this would be a problem.
- leeoniya 5y agohmmm, you might be right. i wonder what steered me away. maybe each SSE response re-sends headers, which can be larger than the message itself? maybe it was inability to do broadcast to multiple open sse sockets from nodejs. i should revisit. https://medium.com/blogging-greymatter-io/server-sent-events-http-2-and-envoy-6927c70368bb https://medium.com/blogging-greymatter-io/server-sent-events...
- xg15 5y ago> maybe each SSE response re-sends headers, which can be larger than the message itself? That's (long) polling, not SSE. The only overhead for SSE are the "data", "event", etc pseudo header names and possibly some chunked-encoding markers. Both are tiny though.
- easrng 5y agoAnother way to solve it could be using a BroadcastChannel to communicate between tabs, do some kind of leader election to figure out which one should start the EventSource, and then have the leader relay the events over the channel.