简体   繁体   中英

Nodejs outbound HTTP requests delayed despite high maxSockets

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 eg 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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM