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)
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.
Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature. It's used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind.
Node. js is not a programming language. Rather, it's a runtime environment that's used to run JavaScript outside the browser.
Node. js is sometimes misunderstood by developers as a backend framework that is exclusively used to construct servers. This is not the case; Node. js can be used on the frontend as well as the backend.
Java uses the concept of multithreading with ease, whereas Node JS does not use the concept of multi-threading like Java does. For large scale projects that involved concurrency, Java is highly recommended, whereas Node JS does not handle the thread and Java, which is the weakest point of this framework.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With