Вопрос

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

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

Это было полезно?

Решение

Not really needed. Since node is event based and a single process would be able to handle thousands of such player pairs. You would be creating "rooms"/"groups"/"channels" for each such pair, assuming that you are using now.js. The nomenclature may vary according to the library you use, but overall approach would be same - to assign all the players who are going to play against each other in same "channel". If you are actually using a child process for each such player pair you are actually killing the purpose with which node.js is built.

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.

Другие советы

The cool thing about Node.JS is that you can make almost all logic in one thread, and through some pretty cool kernel features, Node knows when new socket information is ready to be processed.

One thing that Node is exactly trying to run away is the one-thread-per-connection model. Take a look at this. Node is good for I/O bound applications, so if your game requires too much processing, for example calculating physics objects, Node might not be right for you.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top