How to set max concurrent connections and a queue?
See original GitHub issueI have a for loop that looks something like this:
var urls = [ 'http://example1.com', 'http://example2.com', 'http://example3.com', 'http://example4.com', ... 'http://example10000.com' ]
for (var i = urls.length - 1; i >= 0; i--) {
var options = {
uri: 'http://'+urls[i],
resolveWithFullResponse: true,
timeout: 60000,
jar:true,
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36'
}
}
rp(options).then(function (response) {
console.log(response);
});
}
This works fine for the first 500 iterations, but after 500 all iterations fails. I guess too many connections are open. Can you give an example of a queueing the requests with for example 30 concurrent connections? Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Installing RM - Setting Max connections (WebSphere ... - IBM
To set the Max connections parameter: In the WebSphere® Application Server administrative console, click Resources > JMS > Queue connection factories.
Read more >How to set Max Connection Limit and timeout in HA Proxy
The usage of maxconn parameter will limit the number of connections that can be handled by that particular server at any point of...
Read more >Protect Servers with HAProxy Connection Limits and Queues
In this article, we look at how you can use maximum connection limits and queues in HAProxy to control how much traffic reaches...
Read more >max_connections - TIBCO Product Documentation
max_connections. Maximum number of simultaneous client connections. max_connections = number. Set to 0 to allow unlimited simultaneous connections.
Read more >Limit number of concurrent connections to receipient?
I'm looking for a way to limit the number of connections to a destination endpoint when sending concurrent transactions to a destination.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This could be solved at the Promise part… eg. Bluebird map has a concurrency option.
eg.
Hi @ahansson89 indeed you have to make sure you don’t overload node.js. At one point there are too many outgoing http connections. AFAIK the most important todo is to use a well configured
http.Agent
:The way how I configured the
http.Agent
above is the way I use it in my production environment where I do ~100 requests in parallel. Finding a good value formaxSockets
helped me to make the requests finish sooner. However, I can’t tell what the perfect configuration is that would be needed in your case. You really have to dig into the details yourself.As for the parallel execution and queueing of the requests you can approach this as with any other scenario that somehow involves executing tasks in parallel. I did a quick npm search and maybe this library is a good choice for you: https://www.npmjs.com/package/promise-queue
If you queue your requests keep in mind that the
rp(...)
immediately starts the request. Even if you didn’t call.then(...)
yet. So in order to queue requests that are only started once they are dequeued and processed, you have to wrap them into a function. Withpromise-queue
it would look something like this:I hope this helps.