简体   繁体   English

process.send是* nix / Windows上的同步/异步?

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

I have a Node.js process (not a server) that forks N child processes. 我有一个分配N个子进程的Node.js进程(不是服务器)。 At some point there might be more than 50 CPs. 在某些时候,可能会有超过50个CP。 So I started thinking that if process.send (IPC) is truly blocking then this might be a big penalty experienced by each CP. 所以我开始认为如果process.send(IPC)真正阻塞,那么这可能是每个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. 因为我的程序中发生的事情是每个CP使用process.send将消息发送到单个父进程,以便父进程进行日志记录,以便同步日志记录。 But if process.send blocks then at some point the parent process might become a bottleneck. 但是如果process.send阻塞,那么父进程可能会成为瓶颈。

So the question is - is Node.js IPC blocking or non-blocking on *nix and Windows? 所以问题是 - 在nix和Windows上Node.js是IPC阻塞还是非阻塞? If it is blocking, and if I or someone else really want asynchronous IPC, should I use a message queue or ZeroMQ or something? 如果它是阻塞的,如果我或其他人真的想要异步 IPC,我应该使用消息队列还是ZeroMQ?

Process send has been set to asynchronous, see https://github.com/nodejs/node/commit/56d9584a0ead78874ca9d4de2e55b41c4056e502 进程发送已设置为异步,请参阅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; 这是由于libuv代码的变化; 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. 50个CP不会出现问题,但可能会有500个,具体取决于您的体系结构和消息大小。 At that point I would recommend a message queue that's a bit more fancy. 那时我会推荐一个更有趣的消息队列。 ZeroMQ or plain redis should work. ZeroMQ或普通redis应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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