-
Notifications
You must be signed in to change notification settings - Fork 93
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
Rebase writing system from stream-writed in stream to buffer-writed #48
Comments
The reason why we switched to this was because on tcp and ssl sockets is significantly better to avoid copying the buffers. That slows things down significantly. Ideally the .cork() and writev implementation in Node and ws should take care of chunking and avoiding the problem. There might be something to fix in websocket-stream. |
@mcollina, so if I want to send packet per frame from browser, I must to implement cork() in websocket-stream. Right? |
I think it should be https://github.com/maxogden/websocket-stream/blob/master/stream.js#L154-L166. Why is this not working? |
@mcollina, as I see, writev turned on by options objectMode is false, but objectMode value by default is false. So, by default I getting packet per frame, but that's not realy. I'm getting all properties of packet per frame separatly. I see it on my broker. |
we should create it in not in object mode in MQTT.js. |
What do you mean? We must to implement it in ws connector in mqtt.js? But how? |
In MQTT.js we need to make sure that the websocket stream is not in object mode |
So, if I added property objectMode: false to wsOptions in my connection, I`m getting set up writev handler in websocket-stream. Then in mqtt-packet in generate function stream's try cork(). But writable stream which's piped with writable stream in mqtt.js can't make writev. As I see, I must to imlement writev in _setupStream and to process objectMode for creating writable stream inside that handler. Right? |
What do you mean with "mqtt.js can't make writev". |
What I mean is:
|
Which Writable? This https://github.com/mqttjs/MQTT.js/blob/master/lib/client.js#L245 is used when reading the packets, not when writing them. |
Oh, I see. But I realy can't understand what can I do for to implement sending packet per message. Can you to explain to me, please? |
I do not know where they get chunked up, and where cork() is failing us. https://github.com/maxogden/websocket-stream/blob/master/stream.js#L76 might likely be the issue. |
https://github.com/maxogden/websocket-stream/blob/master/stream.js#L76 probably you are right. Because I'm debugging my app and I see in mqtt-packet stream is Duplexify, but debug way creating Transform stream. And in Duplexify stream objectMode setted in true. |
I think the fix should come to WebSocket stream. |
You are right. Issue in that place. I remove part of logic with duplexify stream, and I get working cork logic.. |
@mcollina, do you know the maintainer of websocket-stream package? He is streel alive?) He don`t have activity on github from october 2018.. |
I have commit and publish rights
Il giorno ven 25 gen 2019 alle 08:19 scarry1992 <notifications@github.com>
ha scritto:
… @mcollina <https://github.com/mcollina>, do you know the maintainer of
websocket-stream package? He is streel alive?) He don`t have activity on
github from october 2018..
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#48 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADL43h1y5Z6tBeiOwtxUbXSVdVL603Jks5vGr4jgaJpZM4aOMp5>
.
|
That's great! Can you spell me: cork/uncork part of logic broken in https://github.com/maxogden/websocket-stream/blob/master/stream.js#L76. When I remove that initial stream by duplexify and leave stream = proxy only, everything works well. Can you tell me why you are doing stream by duplexify and what benefits it gives. |
It is used to handle the delayed open scenario. We can remove it, but we might have to change some other things, as we can’t write until the ws is open. |
Duplexify method obj() set objectMode setting in true automaticaly. And if I extending obj() logic with options parameter, it setup objectMode truely, but don't working anyway. Maybe some issue in duplexify too? |
You might have to add our _writev implementation to the duplexify stream as well. |
That's right, but if I added _writev implementation to duplexify, I'm getting packets separated on 2 chunks. (first byte in first frame, but all another bytes in second frame) W/o duplexify it's working as well (all bytes in first frame). |
Then we should remove duplexify and handle the connection state separately. |
@mcollina, I tried remove duplexify from dependensies, but a lot of duplexify logic needed in server side. I fix it, but need you review. max-mapper/websocket-stream#147 |
@mcollina, and I retested all mqtt.js with that fix - everything ok |
I want to redo the writing system as mentioned in the title. That'll give us less overhead by ws/wss connections, generate less payload when processing fewer socket frames. @mcollina, what do you think about it?
The text was updated successfully, but these errors were encountered: