node.js子进程

扫码查看
本文介绍了node.js子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚这是否是node.js子进程的合适用例:

I'm trying to figure out whether or not this would be a decent usecase for node.js child processes:

我有一个多人游戏,人们参加1v1比赛。我应该为每个匹配项使用子进程吗?

I have a multiple player game where people are engaged into 1v1 matches. Should I use a child process for each match?

推荐答案

不是很需要。由于节点是基于事件的,并且单个进程将能够处理成千上万个这样的玩家对。假设您使用的是(以及)。这里,主进程产生了一个子进程(也称为worker)。工作进程执行实际工作,例如处理HTTP请求,而主进程仅监视工作进程,并在现有工作进程死亡时(由于各种原因)生出新的工作进程。子进程也用于调出非nodejs应用程序。

On the other hand real world use case of spawning a child process is implemented in forever.js(as well as cluster.js). Here a child process ( also know as worker ) is spawned by master process. The worker process do the actual work, say processing a HTTP request, while master process is to only monitor the worker process and spawns new worker process if existing one dies ( due to various reasons ). Child process are also used for calling out non-nodejs applications.

这篇关于node.js子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:47
查看更多