process.send is sync/async on *nix/Windows?
Asked Answered
Y

1

6

I have a Node.js process (not a server) that forks N child processes. At some point there might be more than 50 CPs. So I started thinking that if process.send (IPC) is truly blocking then this might be a big penalty experienced by each CP. Because what happens in my program is that each CP uses process.send to send a message to the single parent process so that the parent will do the logging, so that the logging will be synchronized. But if process.send blocks then at some point the parent process might become a bottleneck.

So the question is - is Node.js IPC blocking or non-blocking on *nix and Windows? If it is blocking, and if I or someone else really want asynchronous IPC, should I use a message queue or ZeroMQ or something?

Yonina answered 6/1, 2016 at 7:11 Comment(0)
E
10

Process send has been set to asynchronous, see https://github.com/nodejs/node/commit/56d9584a0ead78874ca9d4de2e55b41c4056e502

"`ChildProcess.prototype.send()` and `process.send()` used to operate
synchronously but became asynchronous in commit libuv/libuv@393c1c5"

this is due to changes in the libuv code; it has a few drawbacks but if you're concerned about the parent process becoming the bottleneck you could instead use pipes for communication.

50 CPs will not be a problem, but 500 might, depending on your architecture and size of messages. At that point I would recommend a message queue that's a bit more fancy. ZeroMQ or plain redis should work.

Eisteddfod answered 15/1, 2016 at 10:27 Comment(2)
actually, if you read the Github link, it says that process.send has been set to asynchronous, not synchronous, which is good newsYonina
"ChildProcess.prototype.send() and process.send() used to operate synchronously but became asynchronous in commit libuv/libuv@393c1c5"Yonina

© 2022 - 2024 — McMap. All rights reserved.