←back to thread

257 points tosh | 2 comments | | HN request time: 0.502s | source
1. austin-cheney ◴[] No.42071609[source]
We read through the WebSocket RFC, and Chromium's WebSocket implementation, dug through our profile data, and discovered two primary causes of slowness: fragmentation, and masking.

So they are only half way correct about masking. The RFC does mandate that client to server communication be masked. That is only enforced by web browsers. If the client is absolutely anything else just ignore masking. Since the RFC requires a bit to identify if a message is masked and that bit is in no way associated to the client/server role identity of the communication there is no way to really mandate enforcement. So, just don't mask messages and nothing will break.

Fragmentation is completely unavoidable though. The RFC does allow for messages to be fragmented at custom lengths in the protocol itself, and that is avoidable. However, TLS imposes message fragmentation. In some run times messages sent at too high a frequency will be concatenated and that requires fragmentation by message length at the receiving end. Firefox sometimes sends frame headers detached from their frame bodies, which is another form of fragmentation.

You have to account for all that fragmentation from outside the protocol and it is very slow. In my own implementation receiving messages took just under 11x longer to process than sending messages on a burst of 10 million messages largely irrespective of message body length. Even after that slowness WebSockets in my WebSocket implementation proved to be almost 8x faster than HTTP 1 in real world full-duplex use on a large application.

replies(1): >>42072399 #
2. simoncion ◴[] No.42072399[source]
> However, TLS imposes message fragmentation.

If one is doing websockets on the local machine (or any other trusted network) and one has performance concerns, one should maybe consider not doing TLS.

If the websocket standard demands TLS, then I guess getting to not do that is would be another benefit of not using a major-web-browser-provided implementation.