Friday, November 25, 2011

Sporadic delays in BeginRequest of ASP.NET webpages

I've been investigating why some of our ASP.NET webpages sporadically take 10-20 seconds to load, when on average they take 500-700 ms.

The NewRelic instrumentation shows that the delay always happens due to uninstrumented code in BeginRequest.

System.Web.HttpApplication.BeginRequest()0.000 s
13 fast method calls0.000 s
Aptimize.WebAccelerator.OptimizerModule.OptimizerModule_BeginRequest()0.000 s
ASP.global_asax.Application_BeginRequest()0.000 s
System.Web.Security.FormsAuthenticationModule.OnEnter()0.000 s
System.Web.Handlers.ScriptModule.AuthenticateRequestHandler()0.000 s
System.Web.Security.DefaultAuthenticationModule.OnEnter()0.000 s
System.Web.Security.RoleManagerModule.OnEnter()0.000 s
System.Web.Security.AnonymousIdentificationModule.OnEnter()0.000 s
System.ServiceModel.Activation.HttpModule.ProcessRequest()0.000 s
System.Web.Security.UrlAuthorizationModule.OnEnter()0.000 s
System.Web.Caching.OutputCacheModule.OnEnter()0.000 s
System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache()0.000 s
System.Web.HttpApplication+MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()0.000 s
System.Web.Routing.UrlRoutingModule.OnApplicationPostMapRequestHandler()0.000 s
Uninstrumented time 0.000 s
4 fast method calls
After some digging around, I found a few articles that hint this could be due to deadlock issues with Microsoft session module implementation. When you have a page, containing several iframes, these iframes can be concurrently requesting the same session ID from a session state resulting in a deadlock and a delay.

There's a good StackOverflow discussion right here which Demis Bellot pointed me to:
What they recommend to do is to reimplement the session module using MSDN's
custom session handler class ( The only problem is that that class is not thread safe.

So I started tweaking the class and came up with the following source code, which you can download from:
. I am planning to put it into Production next week and measure the results.
Simple Apache benchmarking of default MS session handler and this one, result in almost identical performance.



I'm experiencing something similar. What were your results with your code?

The results were positive. It helped.
We had to further tweak the session module to persist the data in a global distributed cache (otherwise it didn't get shared between servers). But the timeouts in beginrequest got eliminated.

Would you mind setting up a small project on e.g. GitHub with the source code so that the community can give coordinated feedback and maybe fix/improve your solution in case of any problems or shortcomings? That would be a great move, I think :-)

Thanks anyway for writing this up. I also ran into this problem only thanks to New Relic, by the way.

Does this work with mode="StateServer"? We don't need cross-server state management but we don't want state disappearing every time we update our code, so that's why we use the built in state server. I looked at the code and I can't see any way this version explicitly supports StateServer, so I was wondering if maybe I'm just missing some implicit support?

Note, AngiesList implemented a custom session module using REDIS distributed cache:

You could try using that for cross-server state management.

Hello Alaxander,

Thanks a lot for the nice post! We also see similar pattern in our New Relic for our ASP.NET application. I need your expert views on following things:

1. Our application is using "System.Web.SessionState.SessionStateModule" -- I think this is the default one for .NET correct? And this also has same issue what you have described in this post? Our config. is as below:

2. What's your inputs fro Apache Benchmarking? As per my understanding with your improved logic Req/Sec should increase and Response time should decrease -- correct? Or any other things to monitor?
3. This issue exists for all ASP.NET applications? Or any specific ASP.NET version? This issue applies to all heavy request loaded ASP.NET application only correct?

Keenly waiting for your expert views!

Thanks again,

Tks for the post and code.
I try to use it in my project. i added the relevant code from your download, compiles well, and added:

to httpmodul section.
It works... but when i put breakpoints all over your code, it never hits, so it looks for me, as it is not used in my project, means, the session runs with normal session inproc implementation. can that be ? do i miss something additional to the webconfig ?

This comment has been removed by the author.

Thanks for article. However it is not clear if this module is going to work with standard MS SQL Session provider. Module should call provider, right? Could you clarify please?

Thanks for your crystal clear explanation.

dot net training in chennai

Coding is very useful..Thanks for the sharing the post with lot of information..

Mariposa negra (African american Butterfly): This kind of gripping motion picture uses fake omega, any university trainer searching for payback for your murder regarding the girl fiancé. Made in the particular 1990s, this kind of motion picture is approximately corruption and also payback, and also occasionally will be dim yet alluring. L . a . Teta Asustada (The particular Dairy regarding Sorrow): Peru’s initial Oscar nominated motion pictures justifies every one of the consideration that omega replica sale. That uses the character Fausto, a girl having difficulties to be able to appropriately bury the girl mommy. From the particular outskirts regarding Lima, the particular extraordinary conflict motion picture provides eerie Quechua melodies plus a fantastic plot of land. When preparing to get a contest or perhaps education being competing, despite having one self, iwc replica uk in which help observe and also document any runner's info are usually crucial. Mileage, place, heartrate and also rate are typical important factors which can be effortlessly identified using these gadgets. This is really beneficial details to learn just what locations needs to be dedicated to. Several also have the capability of being plugged into a pc so that the particular person can easily examine and also examine the data above a great elapsed breitling replica uk of energy. Education to get a contest can be a extended and also monotonous method being a runner searches for to boost equally velocity and also staying power. The size of the particular contest can be a important determinant inside the amount of a long way they must sign weekly. Furthermore, many individuals normally have any cartier replica for your time frame where they wish to combination the finish series. They want any way in which to be able to continually evaluate the particular development made in each and every work.

I am following your blog from the beginning, it was so distinct & I had a chance to collect conglomeration of information that helps me a lot to improvise myself.
Web design training in chennai

Indeed it all begins at home and then school and then college. But it is at the college stage where you need to make some really important decisions. From what you are going to study to where you are going to study, these are crucial questions that need answers Pass Guide 70-411 PDF

Your article is so informative. The field of web design and development is all about creating attractive website that provide smooth browsing experience to user. Your website is strict example of attractive website design. Web designing course in Chennai

Looking for a career in technology industry? Wonder what are the languages that will give just the right start to your career?
Over to the hottest programming languages you can learn in 2015.

Dotnet Training

There are lots of information about hadoop have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get to the next level in big data. Thanks for sharing this.

.net training in chennai

Thanks for the notes that you have published here. Though it looks familiar, it's a very good approach you have implemented here. Thanks for posting content in your blog. I feel awesome to be here.

cloud computing training chennai
Cloud computing training centers in chennai
hadoop training in chennai

Informative article!!! Being flagship too for Microsoft, Asp.Net is loaded with various essential tools that allow developers to build robust web applications. PHP Training

This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
Python Training in Chennai|Python Training

There are lots of information about latest technology, like Hadoop cluster is a special type of computational cluster designed specifically for storing and analyzing huge amounts of unstructured data in a distributed computing environment. This information seems to be more unique and interesting. Thanks for sharing.
Big Data Training Chennai | Big Data Training | Hadoop Course in Chennai

I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
Python Training in Chennai|Python Training|Python Training Institutes in Chennai

Learning new technology would give oneself a true confidence in the current emerging Information Technology domain. With the knowledge of big data the most magnificent cloud computing technology one can go the peek of data processing. As there is a drastic improvement in this field everyone are showing much interest in pursuing this technology. Your content tells the same about evolving technology. Thanks for sharing this.

Hadoop Training in Chennai |
Hadoop Training Chennai

I am reading your post from the begining, it was nice to read and you are mentioned so many important points to improve my skill set as good way, keep sharing
sap training in Chennai|SAP Course in Chennai|SAP Training|SAP training in chennai

Excellent post!!! The future of .net application development is on positive note. It offers huge career prospects for talented professionals all over the world. Training on .net technology will ensure good salary package. DOT NET Training in Chennai | .NET Training in Chennai

Excellent post!!! Selenium automation testing tool makes your software validation process lot simpler. Keep on updating your blog with such awesome information. Selenium Training in Chennai | Selenium Course in Chennai | Best Selenium training institute in Chennai

Web technology is the best thing that is dominating the world today(web designing course in chennai ), every business needs a web developement in house team(web designing course). The content you have provided here also tells the same. Thanks for providing such a wonderful informtaion in here(web designing training in chennai). Keep blogging like this.

Post a Comment