10

I am facing a strange issue while using NodeJS and Socket.io.

Server which receive data via ZeroMQ. That work perfect. For each message from ZeroMQ, I used sockets.volatile.emit to send that to all connected clients. The issue arise only for large number of connected accounts (more than 100), it seems there is a queue on the sending to clients (client receive message in delay that keep increasing)

Note : Each connected client received each message from ZeroMQ, so basically for more client there is more data sent over the socket.IO.

Via Logs/Debug i know the receive from ZeroMQ has no delay and all works on that part. The emitting seems to have a queue or delay that keeps increasing.

The messages rate is 80 messages/sec for each client.

Note: NodeJS 0.10.20 and Socket.IO 0.9.16.

How can I control that to prevent client received old messages ?

Community
  • 1
  • 1
shay
  • 111
  • 3
  • If you like you can post some code, and we can find a solution, seems that your not the only one having this problem? – Simon Dragsbæk Sep 09 '15 at 07:13
  • yeah some code would be helpful, or at the very least describe what happens between when the server receiving the ZeroMQ message and when the server writes to the socket. – strider Oct 28 '15 at 18:35

2 Answers2

13

Checkout this article it will tell you a lot of the basic mistakes and it's, about blocking the event loop which seems pretty similar to what your doing.

Maybe use tools such as: Debug and Blocked i think it would help solve you'r issue. Both to debug where you creating a bottleneck on performance & other basic issues.

Alternatively hook your node project up on PM2 and bind it to Keymetrics.IO this will give you a good view into your server and why it's running slow and why you make a performance bottleneck.

Its hard to solve your problem without code examples but here is 3 reasons why your app or you could create bottlenecks (maybe unknowingly):

  • Parsing a big json payload with the JSON.parse function.

  • Trying to do syntax highlighting on a big file on the backend (with something like Ace or highlight.js).

  • Parsing a big output in one go (such as the output of a git log command from a child process).

More info in the first article in section 2 called "Blocking the event loop"

A question related to yours, this one.

Wanna know more about the Event loop i can warmly direct you to a tread "How the single threaded non blocking IO model works in Node.js"

Here is a model of the Node.js Processing model, to see what happens on the event loop and its surroundings

Node.js processing model

Community
  • 1
  • 1
Simon Dragsbæk
  • 2,367
  • 3
  • 30
  • 53
0

If it turns out that you're not blocking the event loop in any terrible way, then you might be hitting the limits on what socket.io can handle for your specific application. If thats the case then you might consider scaling up your instances.

Check out this article for more information: http://drewww.github.io/socket.io-benchmarking/

strider
  • 5,674
  • 4
  • 24
  • 29