ASP.NET MVC + jQuery + IIS6: multiple Ajax requests

I'm not sure where the problem is ...

I have an ajax request that checks the tracking information for a package on a package listing page:

$(".fedex_status").each(function() {

    var item = this;

    // some code to construct tracking_url

    $.ajax({
         type: "GET", 
         url: tracking_url, 
         async: true, 
         cache: false, 
         success: function(data) { $(item).html("(" + data  + ")"); }, 
         error: function() { $(item).html("request failed...");} 
         });
 });

      

So if there are 10 packages on the page (10 things with the "fedex_status" class), 10 requests are generated. The queries work fine, but the results are returned in turn (sequential). I added a timestamp to start and stop the request in the controller action:

    public ActionResult Fedex(string trackingNumber)
    {
        DateTime requestStart = DateTime.Now;

        TrackingService tracking = new TrackingService();

        string status = tracking.FedexTrackingNumberStatus(trackingNumber);

        return Content(status + " - " + requestStart.ToString("hh:mm:ss.FFF") + " - " + DateTime.Now.ToString("hh:mm:ss.FFF"));
    }

      

None of the timestamps overlap. Thus, the controller handles requests one at a time. It sounds cheesy.

Now the ajax request should be in parallel. It definitely returns immediately (asynchronously). When I look at the IIS logs, the requests have the same timestamp when the controller action is returned.

So my question is: jquery doesn't send all ajax requests in parallel or IIS or ASP.NET only process requests sequentially. I'm a big noob with IIS and ASP.NET technical details, so maybe it was misconfigured forever and only responds to one request for all (only its internal use, low traffic). However, I'm also an idiot in jquery and not sure how to test when requests actually get fired (all I know is the $ .ajax call returns immediately).

Thanks!

+1


a source to share


3 answers


In theory, ASP.NET with session state enabled locks the session for each user request, processing them sequentially. I don't think you can painlessly disconnect a session for an MVC project because TempData for example uses the default session. But you can try.



EDIT: Here's a related question

+4


a source


Your code works like on my computer. I had to insert any artificial delay with Thread.Sleep in order to see it in action, although due to the unacknowledged requests being executed so quickly that they appeared, they were all completed at once.

 System.Threading.Thread.Sleep(1000);

 return Content(String.Format("Thread #{0}, Started = {1:hh:mm:ss.FFF}, Completed = {2:hh:mm:ss.FFF}, Duration = {3:hh:mm:ss.FFF}, Result = {4}",
       System.Threading.Thread.CurrentThread.ManagedThreadId,
       requestStart,
       DateTime.Now,
       DateTime.Now.Subtract(requestStart),
       status));

      

A quick test on my machine using Firefox and connecting to the Visual Studio Embedded Web Server showed that two requests were being executed simultaneously on the client and processed by two different threads on the server.



As far as I know, a limited number of allowed concurrent requests are allowed by the browser. Here's another post that is on SO that covers every value for each of the popular browsers: How many concurrent AJAX (XmlHttpRequest) requests are allowed in popular browsers?

EDIT: I reread your post and saw that you mentioned IIS 6. I don't have access to IIS 6, but running it on an IIS 7 web server with a 5 second artificial timeout (Thread.Sleep) showed that multiple requests were being processed at the same time different server streams. None of them are launched in TOTAK at the same time, so another queue may occur on the server, but with a delay of 5 seconds, it is easy to notice that in Firefox 3.0 I have at least 6 concurrent requests at a time.

+1


a source


You are calling your ajax request every time you find an element with class .fedex_status.

Your string

$ ("fedex_status"). Each

says this every time you find an element with the class .fedex_status.

0


a source







All Articles