GithubHelp home page GithubHelp logo

Comments (26)

mcollina avatar mcollina commented on June 9, 2024

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.

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

@mcollina, so if I want to send packet per frame from browser, I must to implement cork() in websocket-stream. Right?

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

I think it should be https://github.com/maxogden/websocket-stream/blob/master/stream.js#L154-L166.

Why is this not working?

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

@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.

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

we should create it in not in object mode in MQTT.js.

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

What do you mean? We must to implement it in ws connector in mqtt.js? But how?

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

In MQTT.js we need to make sure that the websocket stream is not in object mode

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

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?

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

What do you mean with "mqtt.js can't make writev".

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

What I mean is:

  • the writable stream (in websocket-stream) is piped with the writable stream in mqtt.js
  • the latter stream (in mqtt.js) can't peform writev

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

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.

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

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?

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

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.

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

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.

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

I think the fix should come to WebSocket stream.

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

You are right. Issue in that place. I remove part of logic with duplexify stream, and I get working cork logic..

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

@mcollina, do you know the maintainer of websocket-stream package? He is streel alive?) He don`t have activity on github from october 2018..

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

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.

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

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.

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

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?

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

You might have to add our _writev implementation to the duplexify stream as well.

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

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).

from mqtt-packet.

mcollina avatar mcollina commented on June 9, 2024

Then we should remove duplexify and handle the connection state separately.

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

@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

from mqtt-packet.

scarry1992 avatar scarry1992 commented on June 9, 2024

@mcollina, and I retested all mqtt.js with that fix - everything ok

from mqtt-packet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.