CHAPTER 13

image

Multithreading with Clusters

There are a lot of detractors out there arguing against the use of Node.js, many of whose arguments are rooted in the myth that Node.js-based systems have to be single-threaded. Nothing could be further from the truth—and with the cluster module, we can effortlessly fork a Node.js process to create multiple processes. Yes, each process will still be single-threaded and be blocked by inapt synchronous code or some laborious processes (such as hashing of passwords). However, the whole system, now consisting of a few processes, won’t be blocked.

In the case of web apps, the processes can listen on the same ...

Get Pro Express.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.