Creating an app cluster
One common argument against Node is that it is single-threaded and therefore does not perform well.
This argument is outdated and invalid—now Node comes with a module called cluster
, using which we can run multiple processes of an app, essentially multiplying the performance of the app on multi-core machines, which most modern computers are.
The performance gain is more obvious when the app is processor- and memory-hungry, and is data-intensive. "Hello World" apps are likely to show little to no improvement in less stressful tests.
Note
The cluster
module is still experimental, so the API may change in the future. But the module itself is likely to be there for good.
Let's write two sample apps to find out whether the performance gain by using cluster is true or not. We will make sure these apps perform the same set of resource-intensive operations.
Here is the first app, a very basic Express app that programmatically generates a huge amount of data and sends it to the...