-
Notifications
You must be signed in to change notification settings - Fork 114
Implement WebSocket compression #19
Comments
@Tratcher let's discuss this (and other WebSockets work) when you're back. |
This would be a great addition. Especially when you are using SignalR as this would help keep the communication to the browser much smaller when sending repetitive $type information. It would be nice if this could be done as part of the core instead of trying to hack it in as an add-on after the fact if it's even possible at the higher levels without ripping out all the base levels. |
Any progress on this? I have a server app that has a dependency on websockets compression and none of the libraries that support compression are ported to Core so its blocking me porting the whole app to Core. Would be great to have native websockets compression support so that no additional libraries are needed. |
No progress to report, so far you two are the only ones that have asked for it. |
Hi, Also its not clear what to do about client websockets - an earlier issue just closed about the client mentions to use 'ClientWebSocket' from System.Net, are there plans for a Core version? |
No plans for it this milestone, it's a large feature and there's been minimal interest. Yes, ClientWebSocket will be available for Core. |
I think there is minimal knowledge not necessarily interest. I don't think many people are aware of this level of detail of the spec. They might not even know of the possible gains they could get with such a feature. We use SignalR as our primary push notification system. With JSON serialization of objects there is a huge communications gain by adding in compression, especially for arrays of objects. We implemented our own compression using LZString and a custom serializer to get a reduction in bandwidth of about 90-98% depending on the messages. This is even with base64encoding which cause some loss of efficiency. Other SignalR users would likely gain from this as well. This means that out of the box you could offer an option that could save a huge amount of bandwidth for any large or even small SignalR user. I think if you keep this audience alone in mind there are likely thousands who would be interested in this gain. If this was implemented at the lower levels and had proper browser support, the overall impact of the compression would be greatly reduced compared to the hacks we have had to put in place or the effort required to write custom serializer to reduce the data load. If it was implemented with SignalR in mind it might also be possible to save space on the SignalR Message bus if messages were passed to the bus already compressed. |
My use case is similar (and likely quite common for websockets), use of JSON between client and server is easy to blow out the package size significantly and permessage-deflate extension support in ASP Core would see some significant speedups for websockets users. Even though Edge does not (yet) support this extension all the other popular browsers do. Given the large focus on Kestrel's raw performance (which is excellent) it would be nice to see the same performance considerations prioritised for websockets use as well. But I understand it will take time, so thanks for considering it for a future milestone. |
@davidfowl would SignalR use WS compression? |
Implementation notes:
ReceiveAsync is easier, it could:
The compression extension could not be correctly implemented as wrapper over the current WebSocket API due to the framing requirement. Compression either needs to be built in or the API needs to expose additional frame fields (e.g. RSV1). I'll consider the extension negotiation separately as the handshake APIs differ in System.Net, System.Web, and Microsoft.AspNetCore. We also need to verify that the Sec-WebSocket-Extensions header(s) flow well end-to-end. Intermediaries like ANCM have had problems with other optional headers like Sec-WebSocket-Protocol. For that matter IIS and WinHttp would have to implement this extension as well, their APIs don't allow ANCM to proxy opaque websocket frames. |
Possibly? Do all browsers support it? Does it transparently fallback if it isn't supported client side? |
The client has to request it, just like subprotocol. Need to research where else it's supported. |
FYI. Here is a c# example of an websockets implementation with compression. Thanks for looking into it. |
@deandob interesting. They use a completely different WebSocket API abstraction that's message based and directly exposes the extensibility flags. Then they wrap the base implementation with another that manages the compression. However, they don't have a way to enable/disable compression on a per message basis. |
OK thanks. So I guess it is still a ways away then? Need any community help? |
The object model issues mean that implementing this will require significant effort. That won't happen without clear customer demand. The best thing you can do right now is help gauge interest. |
The suggestion to overload WebSocketMessageType with CompressedBinary and CompressedText is appealing from a usage perspective. It makes the availability of the feature noticeable via Intellisense and naturally works on a per-message basis. It's not as good from an API purist perspective as we're adding two enum items to cover a single flag. I think a new overload of SendAsync is best. Compression could be part of a something like a new MessageOptions [Flags] enumeration as its first entry (alongside None = 0). Various other per-message on/off switches could easily be added later. |
Most of this work needs to be done in https://github.com/dotnet/corefx/issues/15430, ASP.NET only implements the handshake. |
I'm currently being impacted by this issue: I'm converting a polling-based process from XHR to a WebSocket and have discovered that although the site is now faster on high-speed connections (latency reduction via data pushes from the server at the exact moment of readiness), it's slower on low-speed connections (data takes 10x more bandwidth). |
Any updates on this? This feature would be extremely beneficial. |
No, this is blocked on https://github.com/dotnet/corefx/issues/15430. |
I'm still looking for this feature and with a sizable SaaS app about to go live that would benefit considerably from compression I'm about to jump onto a 3rd party websockets library. I'm surprised how little interest there has been on this as compression would benefit most websockets use-cases. |
Any update on this? |
Also eager for this, rolled our own base64 compression on top manually, but this is a big hack. |
https://tools.ietf.org/html/rfc7692
Autobahn test section 12
The text was updated successfully, but these errors were encountered: