Member-only story
How Node.js performance depends on available CPU count
JavaScript is executed in a single thread. Does execution time of a script depend on a number of processors?
The answer to the question seems so obvious that it warrants some validation.
Google cloud is a nice place for experiments with different numbers of processors. You can create a virtual machine, install anything once, and then keep changing the number of CPUs or the memory size in the virtual machine settings. The most complicated part in changing a machine’s characteristics is waiting for the virtual machine to restart.
In this post I describe three experiments.
First, I check if additional CPUs can reduce the execution time of a time-consuming computation that does not depend on anything except JavaScript engine. Then, I check if Node.js reads files faster if there are more processors. Lastly, I check if throughputs of a Node.js server and HTTP client depend on the number of processors.
Computation time with different numbers of CPUs
I measure the time required for Node.js to calculate 40th Fibonacci number using a inefficient algorithm that efficiently consumes time:
// fibonacci.js…