molnarg / node-http2

An HTTP/2 client and server implementation for node.js
MIT License
1.79k stars 185 forks source link

I am testing with presure #204

Open gridnow opened 8 years ago

gridnow commented 8 years ago

I am running the following function for thousands of times:

function request() {
    var request = process.env.HTTP2_PLAIN ? http2.raw.get(options) : http2.get(options);
    // Receiving the response
    request.on('response', function(response) {
        response.on('data', function(data) {
        });
        response.on('end', finish);
    });
    request.end();
}

And I get 2 problems: 1, Memory usage grows sharply! 2,sometimes with error:

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNRESET 127.0.0.1:8080
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1061:14)

Any help is appreciated!

gridnow commented 8 years ago

sometimes with error: Error: read ECONNRESET at exports._errnoException (util.js:953:11) at TLSWrap.onread (net.js:563:26)

gridnow commented 8 years ago

my full piece of code:

//var heapdump = require('heapdump');
var fs = require('fs');
var path = require('path');
var http2 = require('..');
var urlParse = require('url').parse;

// Setting the global logger (optional)
http2.globalAgent = new http2.Agent({
  rejectUnauthorized: true,
  log: require('../test/util').createLogger('client')
});

// Sending the request
var url = process.argv.pop();
var options = urlParse(url);

// Optionally verify self-signed certificates.
if (options.hostname == 'localhost') {
  options.key = fs.readFileSync(path.join(__dirname, '/localhost.key'));
  options.ca = fs.readFileSync(path.join(__dirname, '/localhost.crt'));
}

var r=0;
var finished = 0;
var max_req = 1000;
var times = 30000;
var reqid = 0;

function request() {
    options.path = "/" + reqid;
    var request = process.env.HTTP2_PLAIN ? http2.raw.get(options) : http2.get(options);
    request.reqid=reqid++;
    request.on('error', (e) => {
      console.error(e);
      console.log(e.stack);
      finish();
        });
    // Receiving the response
    request.on('response', function(response) {
      response.on('data', function(data) {
            var mine = "/" + request.reqid;
        //console.log("mine = ", mine, " got is ", data.toString());
        if (mine != data.toString()) {
            console.log("got data = " ,data.toString());
            console.log("mine data = ", mine);
        }
      });
      response.on('end', finish);
    });
    request.on('socket', (socket) => {
        //console.log("socket event");
        //socket.emit('agentRemove');
    });
}

run_once();
// Quitting after both the response and the associated pushed resources have arrived

function run_once() {
    for (r = 0; r < max_req; r++) 
    {
        //console.log("Making request ", r);
        request();
    }
}

function finish() {
  //console.log("finished = ", finished);
  finished += 1;
  if (finished === max_req/*(1 + push_count)*/) {
    finished = 0;
    //  global.gc();
        run_once();
  }
}
ksmithut commented 8 years ago

What are the specs on your computer? Do you know the max sockets setting?