react-server675fbba4
react-serverfilesdocssrcpagesen(pages)featurescluster.mdx
docs/src/pages/en/(pages)/features/cluster.mdxmdx1.8 KiB2583b246

title: Cluster mode category: Features order: 10 contents: false

Cluster Mode

When you're using the node.js runtime environment, you can start your @lazarv/react-server in cluster mode with your production build. In cluster mode, you can utilize all the CPU cores of your machine to achieve blazing fast performance. You can enable cluster mode by setting the REACT_SERVER_CLUSTER environment variable to the number of cores you want to use or just provide any non-number value to use all the cores available on your machine.

Starting @lazarv/react-server in cluster mode is as simple as setting the REACT_SERVER_CLUSTER environment variable to the number of cores you want to use or for example true, enabled, yes, on to use all the cores available on your machine. The following example shows how to start @lazarv/react-server in cluster mode using pnpm with 8 worker threads.

REACT_SERVER_CLUSTER=8 pnpm react-server start

The following example shows how to start @lazarv/react-server in cluster mode using pnpm with all the cores available on your machine.

REACT_SERVER_CLUSTER="on" pnpm react-server start

You can also enable cluster mode by setting the cluster option in your react-server.config.json file.

{
  "cluster": 8
  ...
}
{
  "cluster": "on"
  ...
}

In cluster mode, if a worker process dies unexpectedly, it is automatically restarted. During graceful shutdown (SIGTERM/SIGINT), the primary process waits for all workers to drain their connections before exiting. See the HTTP layer page for tuning shutdownTimeout and other production server options.

Note: It's best to not use more cluster workers than the number of CPU cores available on your machine.