8

SSE is based on HTTP protocol, and ws requires one time HTTP upgrade.

For a small user base, I understand, WebSocket is way too good over SSE.

I am worried about how much difference will it be for 10,000 user chat system. Here the major concern is:

For WebSocket, I will have to run a loop for 10,000 connections to emit a message every time a new message is received.

For SSE, there is no loop, but a single server-sent event that will stream data to 10,000 users.

To me, Looking on paper it looks like SSE is best for such a large number, especially when numbers of connected clients will keep increasing to 20,000, 100,000. There is no 10,000 value loop running for every new message.

Is it practically true as well? I tried searching quite some performance benchmark for WebSocket vs SSE but can't find any.

Please confirm, if SSE will have better performance and low server resource utilization over WebSocket for emitting / streaming messages to such a large no. of users?

John Cargo
  • 1,839
  • 2
  • 29
  • 59
  • Does this answer your question? [WebSockets vs. Server-Sent events/EventSource](https://stackoverflow.com/questions/5195452/websockets-vs-server-sent-events-eventsource) – Scott Stensland Aug 26 '20 at 10:46
  • 1
    @ScottStensland - I already read the information shared in your URL and it has the only definition, meaning, and advantages one over other. I am already aware of the information. But my concern here is the "Performance Gap" for one over other on the server especially for large numbers where WebSocket starts falling slowly with growing numbers. For example: "10K users chat room group" <- here on WebSocket for every message emit a loop will run for 10K connection, but on SSE, there is no loop, it's just a stream to throw to subscribers. Would love response from someone who has done this before! – John Cargo Aug 26 '20 at 10:59
  • @JohnCargo, I'm exploring SSE and Websocket. Did you find the answer? It would be helpful for the community if you could share it with us. – Sanjay Sharma Nov 26 '21 at 05:55
  • @SanjaySharma - This can be helpful ~ https://stackoverflow.com/a/5326159/2819754 – John Cargo Nov 26 '21 at 11:46
  • Maybe worth a read as well, especially regarding performance: https://www.timeplus.com/post/websocket-vs-sse TLDR: performance is very similar, bottleneck is client CPU (especially in chrome as one process handles all the network traffic), WS seems to use slightly less CPU when pushing the limits, in real world scenarios SSE seems to have a slight edge in terms of CPU usage – exside Dec 09 '22 at 19:33

2 Answers2

0

For broadcasting sse faster because websocket protocol has to decode/encode data. you have to loop both of them. but if you use sse you should send data with post protocol which is slower than websocket.

grijjLY
  • 87
  • 4
0

Here's an article benchmarking and comparing WebSockets vs EventSource (server-sent events):

https://www.timeplus.com/post/websocket-vs-sse

TLDR is, not a big difference, prioritize the functional needs of your app.

trusktr
  • 44,284
  • 53
  • 191
  • 263