Open gridnow opened 8 years ago
sometimes with error: Error: read ECONNRESET at exports._errnoException (util.js:953:11) at TLSWrap.onread (net.js:563:26)
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();
}
}
What are the specs on your computer? Do you know the max sockets setting?
I am running the following function for thousands of times:
And I get 2 problems: 1, Memory usage grows sharply! 2,sometimes with error:
Any help is appreciated!