Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In IIS7, what happens between Application_BeginRequest and Application_PreRequestHandlerExecute?

Tags:

asp.net

iis

I've got some tracing statements with timestamps on an ASP.Net IIS application that gets a lot of traffic. I've got trace statements at the end of Application_BeginRequest and the beginning of Application_PreRequestHandlerExecute in my Global.asax. Occasionally there is a big delay between the end of BeginRequest and the start of PreRequestHandlerExecute, i.e. more than 5 seconds.

What is going on in the lifecycle of an HttpRequest between these two method calls that could be taking so long? This is IIS7 on Windows Server 2008.

Thanks.

like image 841
nganju Avatar asked Feb 17 '11 20:02

nganju


1 Answers

If BeginRequest has already happend and the delay is before PreRequestHandlerExecute, you might want to log the thread id. If it is different, you suffer from ASP.NET thread agility.

A reason for this to happen can be the use of sessions. ASP.NET uses a reader-writer lock on the HttpContext.Current.Session. If you write to this variable, all the other request with the same session cannot run concurrently and are parked in a queue. .NET uses a polling mechanism to check whether the session lock is released.

I would also recommend checken that you've build on Release and that system.web/compilation/@debug = 'false'

like image 92
Jaap Avatar answered Oct 19 '22 21:10

Jaap