Thursday, 10 October 2019

Difference between NodeJS new Agent() and HTTP Keep-Alive header..?

I'm using axios to make HTTP requests.

axios offers the option to specify new http.Agent() in the request config when used in Node.

The http Agent options are:

const agentOptions = {
  keepAlive: true,      // Keep sockets around even when there are no outstanding requests, so they can be used for future requests without having to reestablish a TCP connection. Defaults to false
  keepAliveMsecs: 1000, // When using the keepAlive option, specifies the initial delay for TCP Keep-Alive packets. Ignored when the keepAlive option is false or undefined. Defaults to 1000.
  maxSockets: Infinity, // Maximum number of sockets to allow per host. Defaults to Infinity.
  maxFreeSockets: 256   // Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Defaults to 256.
}

There is also the HTTP header with timeout and max options.

The options don't seem to line up (keepAliveMsecs, maxSockets and maxFreeSockets vs timeout and max), which suggests they are different.

What's the difference between Node's new Agent({ keepAlive: true }) and the HTTP header Keep-Alive: timeout=5, max=1000..?



from Difference between NodeJS new Agent() and HTTP Keep-Alive header..?

No comments:

Post a Comment