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 ?

4

2 回答 2

13

查看这篇文章,它会告诉你很多基本错误,它是关于阻塞事件循环的,这看起来与你所做的非常相似。

也许使用以下工具:调试阻止我认为这将有助于解决您的问题。两者都可以调试您在性能和其他基本问题上造成瓶颈的地方。

或者,将您的节点项目挂接到PM2上并将其绑定到Keymetrics.IO ,这将使您能够很好地了解您的服务器,以及它运行缓慢的原因以及为什么会出现性能瓶颈。

没有代码示例很难解决您的问题,但以下是您的应用程序或您可能会造成瓶颈的 3 个原因(可能在不知不觉中):

  • 使用 JSON.parse 函数解析大型 json 有效负载。

  • 尝试在后端的大文件上进行语法突出显示(使用 Ace 或 highlight.js 之类的东西)。

  • 一次性解析大输出(例如来自子进程的 git log 命令的输出)。

更多信息在第 2 部分的第一篇文章中称为“阻止事件循环”

一个与你有关的问题,这个

想了解更多有关事件循环的信息,我可以热情地引导您了解单线程非阻塞 IO 模型如何在 Node.js 中工作

这是 Node.js 处理模型的模型,以查看事件循环及其周围发生的情况

Node.js 处理模型

于 2015-04-08T11:25:26.957 回答
0

如果事实证明您没有以任何可怕的方式阻塞事件循环,那么您可能会达到socket.io可以为您的特定应用程序处理的限制。如果是这种情况,那么您可能会考虑扩大您的实例。

查看这篇文章了解更多信息: http ://drewww.github.io/socket.io-benchmarking/

于 2015-10-28T18:49:54.940 回答