How to regulate sending requests to server?

465 Views Asked by At

I need to send many requests to server 50-100 requests to load data, each response has at least 0.5KB and at most 7KB of data.

I send the requests using ajax as following: (code is simplified)

for (var i=0; i<elements.length; i++) {
    var element = elements[i];
    // make ajax call with element as parameter and update page to show data for element
}

This works for my needs, because I dont need data to come from server in order, and it works most of the time. But sometimes the last few elements dont get loaded and I get communication link failure error in my chrome javascript console.

I am assuming that the server got overloaded, how can I regulate sending requests to make sure I get a response for each request in the shortest time possible?

Notes:

  • I use Spring MVC in the backend
  • I use ExtJS Ajax to make the requests
2

There are 2 best solutions below

0
On BEST ANSWER

I solved this by recursively calling the each request, this way only one request is sent to the server at the time, and overload is avoided.

2
On

Try using seperate loops for your data uploading process. Overloading is the only cause for that Communication failure.