So, I am trying to optimize my node application and my app makes HTTP and HTTPS requests.
From this article from LinkedIn for making node fast it suggests disabling socket pooling to remove the limit of 5 sockets:
// Disable socket pooling
var http = require('http');
var options = {.....};
options.agent = false;
var req = http.request(options)
Now from Mikeal (the developer of Request) on GitHub, he suggests:
require('http').globalAgent.maxSockets = Infinity
To be fair, he doesn't suggest infinity, but you could put any reasonable value there.
Now, my app uses http and https, so I used this code:
var http = require('http');
http.globalAgent.maxSockets = 30;
var https = require('https');
https.globalAgent.maxSockets = 30;
When I do this, I get this error:
TypeError: Cannot set property 'maxSockets' of undefined
Finally, in looking at the HTTP document it doesn't show a "globalAgent", but instead shows just agent.maxSockets.
So, I am wondering first, what is the best syntax for overriding this parameter?
Second, what is an optimal value? Is it based on the amount of memory my server has? Its bandwidth?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…