-
Notifications
You must be signed in to change notification settings - Fork 165
Updated: websocket implementation to support documentwriter. #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add unit tests to ensure data is written successfully.
src/Transports.Subscriptions.WebSockets/WebsocketWriterStream.cs
Outdated
Show resolved
Hide resolved
src/Transports.Subscriptions.WebSockets/WebsocketWriterStream.cs
Outdated
Show resolved
Hide resolved
Co-Authored-By: DSilence <[email protected]>
pekkah
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tests for the writing would be nice. Also don't really get why the custom stream is required...
|
@pekkah, the custom stream is required to be able to write to the websocket in chunks from a buffer. The alternative is to serialize the whole response to memory and then write the whole byte array at once, but this uses more RAM. |
|
Added unit tests for payloads of varying size (from several bytes, to 100 mb). |
Implemented support for new DocumentWriter for websocket transport.
Things to note:
Writing to socket is achieved by using a proxy stream object - WebsocketWriterStream. It solves several issues:
The initial idea of DocumentWriter method has a memory limit of 1 mb per message
There is some overly complex code around buffers in DocumentWriter implementation. Reducing it to a single method that writes to stream is great.
There is a con, however. There is always a need to call the websocket API at lease twice. Not sure how this will affect the performance and not sure how to test this (perhaps, some load test?).
The ProtocolMessageListener was sending a message.Id twice, once as part of ExecutionResult, and once in OperationMessage. I believe this is not requred, but I may be wrong.
Let me know what you think! Should this approach be accepted, it should be possible to remove the "extra" method within the DocumentWriter, and always stick to Stream API for serialization.