-1

I am making a node.js server that makes a lot of ajax requests to download json or html code, to different websites (not ddos/dos). For this language, I was wondering how many requests I can make at the same time without problems. Like is it ok to do like

for(i=0;i<1000;i+=1) {
    callajax();
}

or do I have to do

function call() {
    callajax(call);
}

this sorta calls the next ajax call, when the current one finishes.

If the top one is ok, how many ajax calls can I call at the same time before I have to wait till they return. I don't want problems with non-returning ajax requests.

Can anyone share some insight into this?

Also, lets say I have two servers running on the same wifi network. If both of them runs their node.js server making ajax requests, is that the same thing as doing it from 1 server?

royhowie
  • 11,075
  • 14
  • 50
  • 67
omega
  • 40,311
  • 81
  • 251
  • 474
  • 1
    how fast can you pull a big boat in a 1960 volkswagen beetle vs a 2015 turbo diesel pickup truck? – charlietfl Mar 24 '15 at 00:35
  • Like @charlietfl said, this is dependent on your server's speed + RAM and its bandwidth. You can queue up the calls indefinitely—until you run out of RAM and the process crashes. – royhowie Mar 24 '15 at 00:38
  • When you say queue up calls, does it queue up using the first code above, or the second code or both? – omega Mar 24 '15 at 00:38

1 Answers1

1

This will depend upon several variables.

  1. How many simultaneous sockets is node.js configured to allow (this is a configuration option within node.js)?

  2. If all the requests are going to the same host, then how many simultaneous connections can that host handle?

  3. If the requests take a little time for the receiving server to process, how fast can it process each request and will it be able to process the last request in less time than your timeout value is set to?

In general, it would be best to limit the number of simultaneous requests you send to the same host to something manageable like 5-10 because in most cases you won't actually get better throughput by sending more simultaneous requests, but you could exhaust some resources or hit timeouts with a lot of simultaneous requests.

The actual max value is dependent upon a lot of configuration choices and specifics related to the type of request and would have to be discovered via testing.

jfriend00
  • 683,504
  • 96
  • 985
  • 979