From the course: Advanced Express

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using the Node.js cluster module

Using the Node.js cluster module

From the course: Advanced Express

Start my 1-month free trial

Using the Node.js cluster module

- [Instructor] Node.js runs in a single process, and basically in one thread. This means that it does not fully utilize all CPUs on a host. To remedy this, Node.js provides a cluster module, that will spin up chart processes. Under the hood, Node.js then uses interprocess communication to distribute the load between the chart processes, round robin. Node cluster is not the only way to achieve this. For example, if you use the process manager PM2, as we will do later, it can be configured to scale up to all CPUs as well. Still, to understand the basic principle behind clustering, we will now implement this from scratch using Node cluster. Before we optimize this, let's run a little load test against our current application. So, on the console, I'm using a patch bench, and we want to concur and see if 10, and I'm running one hundred request against the website. This takes a little bit, and we see that we have a time per request of around 39 milliseconds. Now, let's see what we can gain…

Contents