问题 与cluster.fork之间的childprocess.fork有什么区别


简单的问题:cluster.fork与child_process.fork的区别是什么

详情:

  1. 我可以将参数传递给cluster.fork

  2. 我可以通过child_process.fork在同一个端口或unixsock上监听ChildProcess


11589
2018-05-01 03:25


起源

cluster.fork让我发笑,而childprocess.fork却没有。 - dgnorton


答案:


阅读文档: child_process.fork VS cluster.fork

和...之间的不同 cluster.fork() 和 child_process.fork() 只是该集群允许在工作人员之间共享TCP服务器。 cluster.fork 是在...之上实现的 child_process.fork

http://nodejs.org/api/cluster.html


1.我可以将参数传递给cluster.fork

不是根据文档,并且:

> var cluster = require('cluster')
undefined
> cluster
{ isWorker: false,
  isMaster: true,
  fork: [Function],
  _startWorker: [Function],
  _getServer: [Function] }
> cluster.fork.length
0

(一个 功能 length 是它的形式参数的数量)。使用 消息传递 代替。

2.我可以在child_process.fork创建的ChildProcess创建的同一端口或unixsock上监听

大概是的,因为 cluster.fork 是在...之上实现的 child_process.fork。但是,有一个 原因 那 cluster.fork 已经存在,如果你想在同一个端口上侦听。


11
2018-05-01 03:32



工人之间共享服务器? - guilin 桂林
更新的问题 - guilin 桂林
更新答案:) - Matt Ball