Core Modules
Node.js Cluster
Node.js Cluster Module
Node.js Cluster module scales apps across CPU cores with workers.
Introduction to Node.js Cluster
The Node.js Cluster module allows you to create child processes (workers) that share the same server port, enabling you to take full advantage of multi-core systems. Each worker is an instance of the Node.js process, which is ideal for handling heavy loads in production environments.
How Node.js Cluster Works
A Node.js application runs on a single thread by default. However, modern servers have multiple CPU cores, and often, a single-threaded model cannot utilize all available cores. The Cluster module provides a way to create multiple child processes that can share the same server port, allowing you to distribute incoming connections across the workers.
- Each worker is a separate instance of the Node.js process.
- Workers communicate with the main process through inter-process communication (IPC).
- If a worker dies, it can be restarted without affecting the entire application.
- Previous
- Child Process
- Next
- Testing