0

How many simultaneous requests can I make with the request package? I am expecting data back from every request confirming the request was received and processed successfully. Is this hardware or OS dependent? Where do I start looking?

Jimmy Scray
  • 144
  • 2
  • 14
  • Are all the requests going to the same host? And, approximately how many are you sending at a time? And, what results are you getting? This question is a bit theoretical. Why don't you fill in some of your specific details so we can address your specific situation more directly. – jfriend00 Apr 14 '16 at 00:45
  • What does this mean: ***I am expecting data back from every request with confirmation the request went through successfully. Is this hardware or OS dependent?*** Every request you send should get a response of some kind or return an error that it couldn't contact the host. That is not OS dependent in any way. You will either get some sort of error in contacting the server or you will get a response from the server unless your own code is somehow ignoring errors. – jfriend00 Apr 14 '16 at 00:48
  • All of the requests are going to the same host. I would like to send millions at the same time and then process the response of each so I need my program to "wait" for the response. There has to be a limit to how many I can make and wait for. – Jimmy Scray Apr 14 '16 at 01:05
  • Then, the likely practical limit will be determined by the target host (the server you are connecting to) and you would have to test to see what that limit would be since it is highly variable depending upon the target server configuration. It could literally be anything between 1 and several million. More info in my answer below. – jfriend00 Apr 14 '16 at 01:31

1 Answers1

3

One of the more recent versions of node.js does not enforce a limit on outgoing requests (older versions did). If you were literally trying to make millions of outgoing connections at the same time, then you would probably hit a limit on your own node.js server that would be OS specific. But, the practical limit is more likely going to be determined by the target host.

Since all your requests are being sent to the same host, the more likely limit will be determined by the server you are making the requests to. It will have some sort of limit for how many simultaneous requests it can have "in-flight" at the same time before it starts refusing new connections. What that number is depends entirely upon how the server is configured and built. For http://www.google.com, the number is probably hundreds of thousands or millions of requests because they have a huge server farm and requests are balanced across all of them. For some simple single CPU server, the limit would obviously be much smaller than that.

In addition, there will little use in sending zillions of requests to a single CPU server anyway because it won't be able to work on all of them at once anyway.

So, if you want to know what would work best for a given target host, you would have to set up an adjustable test harness so you could test scenarios where you send from 1, 2, 5, 10, 50, 100, 200, 500, 1000 at a time and see what the average response time is and where you start to get errors (if any).

If you don't want to do any of that type of testing, then a reasonably safe choice that doesn't attempt to fully optimize things is to put no more than 5 requests in flight at the same time.

You can either build something yourself to manage to N requests in flight at a time or you can use one of the existing libraries that will do that for you. The Bluebird promise library has a concurrency option on some of it's functions such as Promise.map() which will automatically do that for you for whatever concurrency value you set. The async library also has something similar.


If you want more specific help crafting the code to manage how many requests are in flight at a time or to build a test harness for it, please show us some of your code for the source of all the requests so we have some idea how that works (if it's a giant array of requests or what the source of the URLs is).

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • @jimmyscray - Did this answer your question? – jfriend00 Apr 16 '16 at 04:02
  • Unfortunately it did not. I found out there are a few things that play a factor into this. One being the "pool" connections threshold (I believe this is at the application level). My linux server also has a port range that limits the amount of connections I can have. And last but not least is the amount of memory my script can allocate. I understand the client has an equal amount of factors but we are making the assumption the client has an unlimited amount of connections – Jimmy Scray Apr 22 '16 at 19:02
  • @JimmyScray - Well, you included very little detail on your specific circumstances so it's impossible for anyone to advise you on those issues. If you include more detail on what you want to know about and what your local configuration is, then you will get more specific answers. For example, it can make a difference if all your connections are to the same host or to different hosts. And, of course, there are resource limits you have to live within (memory, sockets, etc...). That is often configuration and OS specific so again giving you specific numbers is next to impossible. – jfriend00 Apr 22 '16 at 19:05
  • @JimmyScray - And, questions like this that include no code and no detailed description of your configuration and specific requirements are hard to provide specific answers to. The generic side of your question could only be answered thoroughly with a very long treatise (like hundreds of pages that covered hundreds of issues, choices and configurations). That's why stack overflow frowns up such broad and general questions as this. They are impossible to provide good, specific answers to which is what stack overflow is built for. – jfriend00 Apr 22 '16 at 19:08