moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 513 forks source link

Messages hang (or sent really slowly) to client #713

Open mitsos1os opened 6 years ago

mitsos1os commented 6 years ago

We have noticed a problem while using Mosca (version 2.7.0) in production.

This is that while there is a connection established between the server and the client, publishing a message to the client (note that both { level: 'trace' } is given to the mosca constructor and `DEBUG='ascoltatore:'`, is set in the environment, in order to have as much as debug info available)*, reaches all the way of writing to the connection here, and last debug message printed is delivering message here.

However while the client is at the time connected through a stable connection (Ethernet), it does not receive the message. The client is using mqtt.js version 1.14.1

So there is no problem with the ascoltatore (we use the MongoDB backend) and the rest of the operation. Unfortunately there is no other debug information available from that point and further down, since it an implementation of readable - writeable streams (with no debug printing), that end up writing to core net/Socket instance of Node... After some seconds like 10-20 the messages are delivered to the client... But the server has neither CPU or traffic load to explain this delay...

My guess is that something goes wrong with the implementation of the custom streams modules(instead of using the native implementations provided by NodeJS) and they reach a state where the stream read buffer is full, so there is a delay until the buffers are drained... But that's a simple estimate...

Any ideas or similar experience?

mcollina commented 6 years ago

Unfortunately I do not have time to look into this.