有多少子进程可以在64位的Wintel PC上的node.js集群产卵? [英] How many child processes can a node.js cluster spawn on a 64bit Wintel PC?

查看:143
本文介绍了有多少子进程可以在64位的Wintel PC上的node.js集群产卵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行并发测试,并为简洁起见,定义为每个欺骗性HTTP请求的处理。它的工作的罚款高达64请求/进程,但对折65.我在一个I5笔记本电脑上运行微软Windows 7(64位),与拉姆4GB。

I was running a concurrency test, and for brevity's sake, defined a process for each spoofed http request. It worked fine for up to 64 requests/processes, but folded on 65. I'm running Window 7 (64bit) on an I5 laptop, with 4GB of Ram.

虽然运行测试我有一个镀铬开放(有少数标签),我想到的是,OS'常见的系统进程也有一定的效果,但我了解得太少Node.js的最低水平明白问题出在哪里。

Whilst running the test I had a Chrome open (with a handful of tabs), and I expect that the OS' common system processes would also have some effect, but I know too little about node.js at the lowest level to understand where the problem lies.

例如,一篇文章表明,它有可能在一个2GB的64位Windows XP系统上运行了超过​​8000的过程:

For example, one article suggest it's possible to run well over 8000 processes on a 2GB 64-bit Windows XP system:

http://blogs.technet.com/ B / markrussinovich /存档/ 2009/07/08 / 3261309.aspx

不过,我跑进了64子进程的数字是相当明显的。

But the 64 child process figure that I ran into was rather conspicuous.

任何想法?

推荐答案

嗯节点是异步的,有没有堵塞,只能由当前的脚本,它可以处理多个连接完美,这样就意味着在高并发,它会使用所有的CPU,但每个过程只能使用一个核心,因为节点没有螺纹。所以,在技术上有什么建议有是有尽可能多的进程为你的内核,一个核心为每个进程。在这种情况下,在高并发节点集群将使用所有的CPU。如果你去更重要的是,你是在浪费你的RAM,并把额外的工作在你的操作系统的调度。除此之外,每个nodejs过程中有一个启动时间。所以这是非常昂贵的,在运行时创建一个nodejs过程。

Well node is asynchronous, there's no blocking, only by the current script and it can handle multiple connections perfectly, so that means on a high concurrency, it would use all of your CPU, but each process can only use one core, since Node is not threaded. So technically what is recommend to have is having as many processes as your cores, one core for each process. In that case, on a high concurrency the Node cluster would use all of the CPU. If you go more than that, you are wasting your RAM and putting extra work on your OS scheduler. Beside that each nodejs process have an startup time. So it is very expensive to create a nodejs process at run time.

从Node.js的文档:

From Node.JS docs:

这些子节点仍然V8引擎的全新的实例。假定至少   30毫秒的启动和10MB的内存为每一个新的节点。也就是说,你不能   创建成千上万人。

These child Nodes are still whole new instances of V8. Assume at least 30ms startup and 10mb memory for each new Node. That is, you cannot create many thousands of them.

结论的最好的办法是只叉为你的CPU内核的数量,这就是:

Conclusion the best thing to do is to fork just as the number of your CPU cores, which is:

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);
}

我们实际上有一个生产服务器,这样做,可拍摄约1000并发,以及低于10ms的延迟服务于世界你好。

We actually have a production server, doing that, which can take about 1000 concurrency, and less than 10ms latency serving the hello world.

这篇关于有多少子进程可以在64位的Wintel PC上的node.js集群产卵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆