0

I am currently working with project that huge amount of https requests (~15K~20K per second) need be sent via node.js server (node v4.2.6). The general relevant code structure can be seen at final of this post.

We have tried by sending approximately 10~20 https requests per second, and every thing runs successfully, meaning there should not have problems on requests header and body itself.

However, issues occurs when we start scaling up Nodejs server for sending thousands and millions requests per seconds. In this case, it looks like the responses of the requests be sent will not come back ever, instead the Nodejs server will shutdown the socket and throws following exceptions:

{ [Error: socket hang up] code: 'ECONNRESET' }
Fri, 24 Feb 2017 06:08:39 GMT  Caught exception: Error: socket hang up Details: {"code":"ECONNRESET"} Stack: Error: socket hang up
    at createHangUpError (_http_client.js:202:15)
    at TLSSocket.socketOnEnd (_http_client.js:287:23)
    at emitNone (events.js:72:20)
    at TLSSocket.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
    at nextTickCallbackWith2Args (node.js:441:9)
    at process._tickCallback (node.js:355:17)
{ [Error: socket hang up] code: 'ECONNRESET' }
Fri, 24 Feb 2017 06:08:39 GMT  Caught exception: Error: socket hang up Details: {"code":"ECONNRESET"} Stack: Error: socket hang up
    at createHangUpError (_http_client.js:202:15)
    at TLSSocket.socketCloseListener (_http_client.js:234:23)
    at emitOne (events.js:82:20)
    at TLSSocket.emit (events.js:169:7)
    at TCP._onclose (net.js:469:12)

We felt that the problems is caused by https library it self that socket will be automatically shutdown if there are too many requests being sent! Therefore i am wondering is there any bug-fixed version of this https library? or is there any alternative https post/get library?? Any suggestions are appreciated! :-)

var https = require("https");
// do something
option_1.agent = new https.Agent({ keepAlive: true });
var req = https.get(option_1, function(res) {
  res.on('data', function (body) {
    // get the response string
  });
  res.on('end', function () {
    // get the result1
  }); 
});

if (result1 == null) return;
// using result1 to generate option_2
option_2.agent = new https.Agent({ keepAlive: true });
var req2 = https.request(option_2, function(res) {
  res.on('data', function (body) {
    // get the response string
  });
  res.on('end', function () {
    // get the result2
  })
});

if (result2 == null) return;
// using result2 to generate option_3
option_3.agent = new https.Agent({ keepAlive: true });
var req3 = https.request(option_3, function(res) {
  res.on('data', function (body) {
    // get the response string
  });
  res.on('end', function () {
    // get the result3
  })
});

console.log(result3);
Chen Chen
  • 11
  • 1
  • 5
  • Why are you creating multiple agent instances? Have you tried using the same one for *all* of your requests? What is the significance of the `result1`/`result2`/`result3`, they don't seem to be defined anywhere? You might also include what platform/OS (and version) you're on. Have you tried newer versions of node (e.g. v6.x, v7.x) to see if there is any difference there? – mscdex Feb 24 '17 at 06:40
  • I wouldn't be so quick to assume this is only on the https library. This very well could be either an OS issue with the qty of open sockets per process or a timeout issue with so many SSL calculations going on with a single thread and not enough cycles to get decent response times for everything going on. – jfriend00 Feb 24 '17 at 07:01
  • If you think about 20k connections per second, that means you need to be able to create an SSL connection, send the request, read the response, process the response, close the connection all in 0.05ms of CPU time (for each and every connection) all while doing SSL encryption on every packet. That doesn't seem likely with a single process and probably not even with a single network card. – jfriend00 Feb 24 '17 at 07:04

0 Answers0