node.js - Nodejs Max Socket Pooling Settings -


so, trying optimize node application , app makes http , https requests.

from article linkedin making node fast suggests disabling socket pooling remove limit of 5 sockets:

// disable socket pooling var http = require('http'); var options = {.....}; options.agent = false; var req = http.request(options) 

now mikeal (the developer of request) on github, suggests:

require('http').globalagent.maxsockets = infinity 

to fair, doesn't suggest infinity, put reasonable value there.

now, app uses http , https, used code:

var http = require('http'); http.globalagent.maxsockets = 30; var https = require('https'); https.globalagent.maxsockets = 30; 

when this, error:

typeerror: cannot set property 'maxsockets' of undefined

finally, in looking @ http document doesn't show "globalagent", instead shows agent.maxsockets.

so, wondering first, best syntax overriding parameter?

second, optimal value? based on amount of memory server has? bandwidth?

in regard typeerror you're getting, don't errors when setting either http.globalagent.maxsockets or https.globalagent.maxsockets. there's else going on in app.

regarding first part of question, realize you're not restricted using global agent. can create own agent instances , use make requests:

var http = require('http'); var myagent = new http.agent();  http.request({ ... , agent: myagent }, ...); 

requests made using custom agents don't interact global agent @ all. global agent default 1 gets used if don't explicitly specify 1 or opt-out of using agents (by passing false agent value in request options).

so when docs agent.maxsockets, they're referring generic agent class; every instance has property, including global (default) agent – must access through http.globalagent.

the second part of question (optimal maxsockets) tough 1 answer. remember many servers limit number of concurrent connections given ip, , want make sure don't overwhelm server large number of concurrent requests. (with enough requests fired off @ once, you're esentially dosing server.)


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -