Nodejs outbound HTTP requests delayed despite high maxSockets

578 views Asked by At

I am developing a node.js app locally on Mac OS X 10.9.5 that proxies requests for large files on another server. I have tried writing my app using node-http-proxy, and also with a simple http/request one-liner (req.pipe(request()).pipe(res)). Both work fine until I start making e.g. 30 simultaneous requests to my proxy for a large-ish(90MB) file. Tailing the access log on the backend server, I can see that only a portion of my proxied requests appear immediately. The others trickle in many seconds and sometimes minutes later. In some cases, the later outbound requests correspond with the completion of some of the requests that arrived immediately, and in other cases I see no patterns as far as what is unblocking the requests. The number of requests that make it out to the backend server immediately is inconsistent. I have tried setting http.globalAgent.maxSockets to a number much larger than my 30 requests, but this does not make a difference. Any other ideas as to what could be delaying a subset of my outbound HTTP requests?? Thanks!

1

There are 1 answers

1
ctt On BEST ANSWER

Note that there are (at least) two outbound HTTP socket pools. You have properly configured the one for outbound http connections using, http.globalAgent.maxSockets, however, there is another one for https connections, https.globalAgent.maxSockets.

And just as a refresher. From the node docs on the matter:

agent.maxSockets#

By default set to 5. Determines how many concurrent sockets the agent can have open per origin. Origin > is either a 'host:port' or 'host:port:localAddress' combination.