如何修复未充分利用CPU内核的NodeJS?

According to this page Go vs Node.js, Node.js is not showing to be taking full advantage of CPU cores when running cpu-intensive code.

If I use virtualization and simply add more Node.js instances, will I achieve the same performance as Go? I suppose there still will be overheads and one won't be able to achieve the same performance.

You need to install Cluster module of nodejs in order to take full advantage of CPU cores when running cpu-intensive code.

Multiple processes will do. For 4 cpus/threads you need 4 Node.js processes to make use of them. That requires a workload that can be split between processes though.

Node.js provides the Cluster module to distribute socket connections between multiple worker processes which may help in some workloads, but I doubt this would help any of the benchmark workloads.

Node.js is indeed a single threaded process. However, you can make use of clustering to spawn multiple workers on multiple cores.

If you are not using PM2 for spawning the app, please consider using it. PM2 makes spawning workers on multiple cores super easy.

pm2 start app.js -i max

This command will spawn workers on each available core.

Also, note that if you are using session/sockets then you might face some problems because of clustering.