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
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Tuning Express performance: NODE_ENV and compression4m 6s
-
(Locked)
Tuning Express performance: Further measures2m 2s
-
(Locked)
Add logging5m 3s
-
(Locked)
Using the Node.js cluster module5m 12s
-
(Locked)
Securing an Express application2m 44s
-
(Locked)
Deployment and operation with PM24m 37s
-
(Locked)
Running behind a web server5m 8s
-
(Locked)
-