Martin Hansen
Martin Hansen

Reputation: 5224

IIS delays a lot between each response with async requests

I have a ASP.NET MVC project running on my developer machine with windows 7 ultimate and iis 7.5.

I do the following:

var requests = ["http://myserver.com/news/details/113834",
"http://myserver.com/tag/details?ids=113834&entityType=23",
"http://myserver.com/publish/details?ids=113834&entityType=23",
"http://myserver.com/generalproperty/details?ids=113834&entityType=23",
"http://myserver.com/category/details?ids=113834&entityType=23"];

var f = new Date().getTime();
$.each(requests, function(k,v) {
    $.ajax({
    url :v,
    async : true,
    type :'get',
    success : function(data) {
        console.log(new Date().getTime()  -f );
    }});
})

Then I get the following results(approx) 12, 521,1025,1550, 2067 async result http://martinhansen.no/hostedimages/async.PNG

If I switch the async to false I get : 14,32,49,58,68 sync result http://martinhansen.no/hostedimages/sync.PNG

Seems somewhere the requests are being queued up and after a while it responds only every 500 ish second. I have made my controllers return blank text instead of the database call, so not the database.

Is there a limitation on IIS 7.5 for windows 7? A setting I can change? I'm suspecting a max concurrent requests per user or something similar. And then it "punishes" you by responding every 500 ms only. So that people don't use it as an actual server.

Likely? And is there a way to avoid it?

Upvotes: 11

Views: 5434

Answers (2)

Martin Hansen
Martin Hansen

Reputation: 5224

It have nothing to do with IIS apperantly or IIS on windows 7, I also tried it on a test server and same results.

It was because of limitations imposed by sessionstate, see the "Concurrent Requests and Session State" section at the bottom here: http://msdn.microsoft.com/en-us/library/ms178581.aspx

However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished.

But I still don't understand why it don't fire off the next request right after the the first one is seemingly finished. It seems very fake the 500 ms delay.

I came over this question How to set the ASP.NET SessionState read-write LOCK time-out? that talks about the lock out time for the session state.

System.Web.SessionState.SessionStateModule.LOCKED_ITEM_POLLING_INTERVAL = 500

That's the magic number that I've been searching my code and the interwebs for.. 500! I knew it had to be somewhere.

Anyway, to fix this, I added the sessionstate attribute to my controllers with the option of read-only

[SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
public class BaseController : Controller{} 

Read more about it:

http://afana.me/post/session-less-controllers-and-TempData-ASPNET-MVC.aspx

http://weblogs.asp.net/imranbaloch/archive/2010/07/10/concurrent-requests-in-asp-net-mvc.aspx

I still think something is wrong though, why don't the previous request tell the system that it no longer needs a lock on the sessionstate so that the next request can complete?

Upvotes: 13

Frazell Thomas
Frazell Thomas

Reputation: 6111

How many requests are you sending at once? IIS on Client OSs are limited to 10 simultaneous connections. Above that limit it throws the incoming connection into a queue and processes it when a slot opens up.

This has been the case for a long time in an effort by MS to ensure that client OSes aren't used to cannibalize sales of their server OS platforms.

Upvotes: 1

Related Questions