最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - NodeJS & Socket.IO - Stack Overflow

programmeradmin0浏览0评论

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 ?

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 ?

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Oct 23, 2013 at 10:31 shayshay 1113 bronze badges 2
  • 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 Commented Sep 9, 2015 at 7: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 Commented Oct 28, 2015 at 18:35
Add a ment  | 

2 Answers 2

Reset to default 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 mand 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

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/

发布评论

评论列表(0)

  1. 暂无评论