From the course: Advanced Node.js: Scaling Applications

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Using a cluster module

Using a cluster module

- [Instructor] In Node.js, a single application instance only uses one processor because Node.js is single threaded. Forking your application into multiple instances is required to take full advantage of your hardware. A cluster is a group of node instances that all work together. A cluster is made up of worker processes, the four instances of our app, in a main process, which is the instance that spawns and controls the workers. Let's create a cluster to take advantage of every CPU that is available to us. I'm inside of the Exercise Files, inside of the folder for Chapter One, Chapter One, Lesson Four, and within the Start folder, there's a blank index.js. That's where I'm gonna be adding my code. So the first thing I'm gonna go ahead and do is take a look at the CPUs on this machine. So if I use the OS module, and then invoke the CPUs function, this will give me information about every processor that I have…

Contents