@joystick.js/node

Cluster

How to enable cluster mode in Joystick to fully utilize the processing power of your app's host machine.

In Node.js, the cluster library makes it possible to "fork" your main Node.js process and creat copies of it equal to the number of processor cores on the machine running your app.

So, if we run our app on a single core machine, we'll get a single process. If we run our app on an 8 core machine, we'll get eight processes.

As a convenience, Joystick includes a simple cluster option that you can pass alongside your other joystick.app() options to enable cluster mode.

Example Usage

index.server.js

import joystick from '@joystick.js/node';

joystick.app({
  cluster: true,
  ...
});

Here, we add the cluster option to our joystick.app() options and set it to true. Now, when our app starts (or restarts), Joystick will detect the number of CPU cores available on the machine and fork the main process to match this count.