Question

I'm writing a static web server using Node's 'net' module, and I've had some troubles running stress tests on it.

This is the code of the test itself:

var http = require("http");
http.globalAgent.maxSockets = 100000;
var numOfRequests = 1000;

var options = {
  host: 'localhost',
  port: 9000,
  path: '/first/profile.html', 
  method: 'GET'
};



//Number of current responses.
var currResponse = 0;

//Create 1000 http requests 
for (var i = 0; i < numOfRequests; i++) {

    var req = http.request(options, function(res) {
        console.log("Got response: " + res.statusCode);
        console.log("response num: "+currResponse);
        currResponse++;

    });
    req.on('error',function(e){ console.log('some error occured: '+e.message); });
    req.end();
}

When running on Node v. 0.8.15 (current latest version), for 'numOfRequest' greater than 20, the server nearly collapses - and out of a thousand requests, only ~160 are handled correctly. From the tester side,

I'm using fs.createReadStream().pipe() (with the appropriate parameters, and with entering {end: false} ) to send data over the socket. Also, I call socket.destroy() (where socket is the argument received in net.createServer's callback function) upon timeout (two seconds of inactivity), and socket.end() if I receive "Connection: close" as a header in the HTTP request.

Any help? I've tried everything; switching to http.get(), putting {allowHalfOpen: true} when creating the server, and more - but still, I'm getting "error: write EPIPE" (or, after a while, "error: This socket is closed.") from the server side and "socket hang up" from the client side.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top