process.send在* nix / Windows上是同步/异步? [英] process.send is sync/async on *nix/Windows?

查看:172
本文介绍了process.send在* nix / Windows上是同步/异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Node.js进程(而不是一个服务器),它会分配N个子进程。
某些时候可能有50多个CP。所以我开始想,如果process.send(IPC)是真正的阻塞,那么这可能是每个CP经历的一个很大的惩罚。因为我的程序发生了什么,每个CP使用process.send向单个父进程发送一个消息,以便父​​进程执行日志记录,以便记录将被同步。但是如果process.send阻塞,那么在某种程度上父进程可能会成为瓶颈。

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.

所以问题是 - Node.js IPC在* nix和Windows上的阻塞或非阻塞?如果它是阻塞的,如果我或其他人真的想要异步IPC / IPC,我应该使用消息队列还是零消息等等?

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?

推荐答案

进程发送已设置为异步,请参阅 https:// github .com / nodejs / node / commit / 56d9584a0ead78874ca9d4de2e55b41c4056e502

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"

这是由于libuv代码的变化;它有一些缺点,但如果您担心父进程成为瓶颈,您可以使用管道进行通信。

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 CP不会是问题,但是500可能取决于你的架构和消息的大小。那时候我会推荐一个更有趣的消息队列。 ZeroMQ或纯redis应该工作。

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.

这篇关于process.send在* nix / Windows上是同步/异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆