webpapaya webpapaya - 1 month ago 11
Javascript Question

Why are Websockets faster than Server Sent Events

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 communication like a chat applikation because of the HTTP overhead for XHR.

Answer

I think there are two effects combining 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, compared to a more compact payload and careful protocol design with WebSockets, in a bi-directional communication 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 communication, 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.

Comments