Well, the node is asynchronous, there is no blocking only by the current script and it can handle several connections perfectly, so this means that at high concurrency it will use your entire processor, but each process can use only one core, since the node has no thread. So technically, what is recommended to have has as many processes as there are your cores, one core for each process. In this case, the entire processor will be used on the concurrency cluster node. If you go more, you waste your RAM and add extra work to the OS scheduler. In addition, each nodejs process has a startup time. Therefore, it is very difficult to create a nodejs process at runtime.
From Node.JS docs:
These child nodes are still whole new V8 instances. Assume 30 ms and 10 MB memory for each new Node. That is, you cannot create many thousands of them.
Conclusion The best thing to do is to develop in the same way as the number of your processor cores, namely:
var cluster = require('cluster'); var http = require('http'); var numCPUs = require('os').cpus().length; if (cluster.isMaster) { // Fork workers. for (var i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on('death', function(worker) { console.log('worker ' + worker.pid + ' died'); cluster.fork(); }); } else { // Worker processes have a http server. http.Server(function(req, res) { res.writeHead(200); res.end("hello world\n"); }).listen(8000); }
In fact, we have a production server that can take about 1000 concurrency and less than 10 ms serving the world of hi.
Farid nouri neshat
source share