2

I have a 'tabbed' style web page where once the page loads each tab fires off an Ajax request for their content (using jQuery). The backend is ASP.NET MVC running in Visual Studio so just with the normal 'ASP.NET Development Server' servicing the requests. I am experiencing the following issues:

1) The requests are processed by the web server one at a time. The second request is not dealt with until the first completes. Is this the 'ASP.NET Development Server' running in some single threaded mode? Can I make it multithreaded (and should I make it multithreaded or would this open up a world of pain?)

2) Long running requests kill off subsequent requests. Given that the requests are being serviced one at a time even though I am firing off the ajax request all at once, why do some of the requests fail to even arrive at the web server? This happens once a long request has been serviced. For example:

  • 1st Request (small request) - response okay
  • 2nd Request (large request) - response takes a minute or so but does get serviced.
  • 3rd Request (small request) - request never arrives at the server and jQuery does not report an error.

I have tried increasing the ajax timeout but with no success.


Update: I have found a bug in my code that was messing up the URL to the final request so it looks like this has nothing to do with the request length and ajax timing out (blushes!). Along the way though I have found the useful ajaxManager plugin which is great for queueing up request if that is what you need (http://www.protofunc.com/scripts/jquery/ajaxManager/). Also, thanks for the valid point about using the ASP.NET Dev Server to test against. It is indeed quite different from IIS.

3
  • A sidenote. First, do not performance test your app in Capistrano (Visual Studios development server). It does many things that IIS does not do in production mode. Second, the first request takes more time than the other because your project has to be compiled (the same goes for IIS). Commented Feb 1, 2011 at 14:13
  • @alexn I think that's Cassini Commented Feb 1, 2011 at 14:28
  • 2
    @Omu yeah, need some more coffee :) Commented Feb 1, 2011 at 14:38

2 Answers 2

5

With regards to point 1 bear in mind that if you're using session state then the requests will not perform concurrently - ASP.NET will lock the session state and will only process each request that uses it one at a time. (See the section 'Concurrent Requests and Session State' in http://msdn.microsoft.com/en-us/library/ms178581 for more info) Try disabling session state (if you're not using it of course!) and see if that helps.

Sign up to request clarification or add additional context in comments.

3 Comments

so if one request uses Session["a"] and another uses Session["b"] they can't work concurrently ?
We are using session state so this is a very helpful comment. I can see how session state could case threading issues. Thanks.
@Omu - Yes, if they're for the same session that's correct - doesn't matter if even they're different objects in the session.
0

When ASP.NET see two or more requests from the same user( by checking their SessionID) and session is marked with both Read and Write, then it will execute the first request and queue all other requests such that only one request will execute from the same user at the same time. So we can say that these requests are serialized. To make your requests execute concurrently, you need to either mark your session as disabled or read only.

For example. How to disable session state in application level:

protected void Application_BeginRequest()
{

   if (Request.Cookies["ASP.NET_SessionId"] != null)

   {

       Request.Cookies.Remove("ASP.NET_SessionId");

   }

}

If you want to allow concurrent requests for few controllers and want to maintain session for other controllers. We can filter out the conditions as below: In below example i am disabling session only for the controller namely "Concurrent". All other controllers will maintain session.

protected void Application_BeginRequest()
    {
    
       if (Request.Url.AbsoluteUri.ToLower().Contains("Concurrent") && Request.Cookies["ASP.NET_SessionId"] != null)
    
       {
    
           Request.Cookies.Remove("ASP.NET_SessionId");
    
       }
    
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.