简单的 nodejs http 代理因“打开的文件太多"而失败 [英] Simple nodejs http proxy fails with "too many open files"

查看:58
本文介绍了简单的 nodejs http 代理因“打开的文件太多"而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,忽略它.我打开了一个问题 https://github.com/joyent/node/issues/793

Well, ignore it. I have opened an issue https://github.com/joyent/node/issues/793

尝试运行 http://www.catonmat.net/http-proxy-in-nodejs

var http = require('http');

http.createServer(function(request, response) {
  var proxy = http.createClient(80, request.headers['host'])
  var proxy_request = proxy.request(request.method, request.url, request.headers);
  proxy_request.addListener('response', function (proxy_response) {
    proxy_response.addListener('data', function(chunk) {
      response.write(chunk, 'binary');
    });
    proxy_response.addListener('end', function() {
      response.end();
    });
    response.writeHead(proxy_response.statusCode, proxy_response.headers);
  });
  request.addListener('data', function(chunk) {
    proxy_request.write(chunk, 'binary');
  });
  request.addListener('end', function() {
    proxy_request.end();
  });
}).listen(8080);

在大量请求后失败:

net.js:695
        self.fd = socket(self.type);
                  ^
Error: EMFILE, Too many open files
    at net.js:695:19
    at dns.js:171:30
    at IOWatcher.callback (dns.js:53:15)

OSX 10.6 上的节点 0.4.2

node 0.4.2 on OSX 10.6

推荐答案

您可能会达到操作系统中打开文件的(默认)最大值(对于 Linux,它是 1024),尤其是当您处理大量请求时.例如,在 Linux 中,您可以使用 ulimit 命令增加此资源限制:

You may be hitting your (default) maximum value of opened files in your operating system (for Linux it's 1024), especially if your are doing huge number of requests. For example in Linux you can increase this resource limit with ulimit command:

ulimit -n 8192

这篇关于简单的 nodejs http 代理因“打开的文件太多"而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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