admin管理员组

文章数量:1320661

Hi I currently came accross this paper and I can't figure out why Server-Sent Events are slower for pushing data from a server to a client.

I can see the point that SSE are slower for bidirectional munication like a chat applikation because of the HTTP overhead for XHR.

Hi I currently came accross this paper and I can't figure out why Server-Sent Events are slower for pushing data from a server to a client.

I can see the point that SSE are slower for bidirectional munication like a chat applikation because of the HTTP overhead for XHR.

Share Improve this question asked Apr 15, 2014 at 13:18 webpapayawebpapaya 80912 silver badges21 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

I think there are two effects bining here to cause the claim that WebSockets are "faster" than SSE.

Effect 1: SSE has a Lower Payload to Message Ratio As you noted, in general, the overhead of HTTP requests/responses is larger, pared to a more pact payload and careful protocol design with WebSockets, in a bi-directional munication pattern.

Effect 2: SSE can involve Session Reconnections As @alexsergeyev points out correctly, SSE sessions can reconnect, but in most modern browsers that simply means SSE sessions do get re-created using pooled TCP connections, so the effect on

Combining these two effects, and defining throughput in bytes/second as the metric, I hope we can see that even for uni-directional server to client munication, throughput is better for WebSockets due to both these effects.

As far as I know, as the adoption of WebSocket-aware intermediaries takes off, the role for SSE will be reduced as time goes on. Right now, if you rely on HTTP for your security story, you might choose SSE unless you have hard-real-time requirements. If you do, the Kaazing Enterprise WebSocket gateway has built-in SSO integration for most security systems.

If you look at charts on page 6, you'll see that the claim is based mostly on "server updates" being slower on SSE.

Which is true since server-side events is a technology of pushing data to client, not for sending data to server! Those require new HTTP requests and, likely, establishing new TCP (sometimes TLS) connection which is quite expensive for satellite link and for mobile devices with slow CPU and memory.

That allows authors of the paper to argue that websocket is faster which is not quite correct conclusion to state universally, regardless of the type of the interactions and transferred data.

I am not paring features here. Websocket and SSE clearly solving similar but different problems and should be assessed to be applicable for particular project, there should not be an universal answer to use one or another.

本文标签: javascriptWhy are Websockets faster than Server Sent EventsStack Overflow