How many child processes can a node.js cluster appear on a 64-bit Wintel PC?

I ran the concurrency test and for brevity I defined a process for each faked http request. It worked fine up to 64 requests / processes, but 65 folded. I am running Window 7 (64 bit) on an I5 laptop with 4 GB of RAM.

During testing, I had Chrome open (with several tabs), and I expect that the general OS system processes will also have some effect, but I know little about node.js at the lowest level to understand where the problem lies.

For example, in one article, it is suggested to run more than 8000 processes in a 64-bit Windows XP system with 2 GB:

http://blogs.technet.com/b/markrussinovich/archive/2009/07/08/3261309.aspx

But the 64-bit shape of the child I encountered was pretty noticeable.

Any ideas?

+3
source share
1 answer

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.

+11
source

All Articles