Alex M Alex M - 1 year ago 76
Javascript Question

Server response to multiple asyncronous XHR

I am developing a Web Application that makes multiple simultaneous XHR calls (using Ajax rather than native Javascript).

type: 'POST',
url: 'Services/Service.asmx/MyFunction',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
'something': 'Something'
success: function (data) {
// Do something with the returned data.
error: function (xhr, status, error) {
// Handle the error.

When I debug the application and make two or more calls at the same time, I can see that the XHR calls are made immediately (after page load) by the client but the waiting time associated with those calls to the same web method producing the same response gets progressively longer.

enter image description here

It's as if the server is handling each XHR call one after another rather than in parallel (ie receiving the requests, processing the first one, responding to it, processing next request, etc.).

Is this by design or is their a way to have the server act on each request independently and in parallel?

Answer Source

It all depends on what your backend is and how it's configured. It could be a VPS, it could be a dedicated server, it could be a cloud. It could have one node or several nodes. It can use one database or the databases could be distributed.

Since you noticed that the requests aren't handled simultaneously, in your case it looks like the server had one node / one process / one database. Or maybe it's unable to run these two operations in parallel because the result of the second request depends on the result of the first one.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download