简单问题:cluster.fork 和 child_process.fork 有什么区别
细节:
我可以将参数传递给 cluster.fork
我可以在相同的端口或 unixsock 上监听由 child_process.fork 创建的 ChildProcess
简单问题:cluster.fork 和 child_process.fork 有什么区别
细节:
我可以将参数传递给 cluster.fork
我可以在相同的端口或 unixsock 上监听由 child_process.fork 创建的 ChildProcess
阅读文档:child_process.forkvs 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. 我可以在同一个端口或 unixsock 上监听由 child_process.fork 创建的 ChildProcess
大概是的,因为cluster.fork是在child_process.fork. 但是,如果您想在同一个端口上侦听,则已经存在一个原因。cluster.fork