Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 215
Alexander Mills Avatar asked Jan 06 '16 07:01

Alexander Mills


1 Answers

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.

like image 151
maxwellium Avatar answered Nov 04 '22 08:11

maxwellium