简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM