Lock contention in CacheHelper class.

This is the place to report bugs and get support. When posting in this forum, please always provide as much detail as possible.

Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum, do not report it as a bug.

This is the place to report bugs and get support

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.
Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum.
This thread is closed to new posts. You must sign in to post in the forums.
11/16/2011 4:51:01 PM
Gravatar
Total Posts 1

Lock contention in CacheHelper class.

Hi,

I work in the IIS team at Microsoft. I was running some local performance test against this Web Application and the VS profiler showed me that there is a lot of contention in the method mojoPortal.Business.WebHelpers.CacheHelper.GetSiteSettingsFromCache. According to the profiler, we are locking using an exclusive lock. I would recommend to use a Reader/Writer lock instead, since this is a major contention point for the Web App.

http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlock.aspx (if you need .NET 2.0 support).

Reproduce by:

1. Create a test.txt file and set some content (e.g. "hello").

2. Disable kernel cache in IIS.

3. Do lots of concurrent requests to /test.txt

4. Analyze profiling data (sample only).

Hope this helps.

Daniel.

 

 

 

11/17/2011 6:47:02 AM
Gravatar
Total Posts 18439

Re: Lock contention in CacheHelper class.

Hi Daniel,

Thanks for your post. I wonder if you can confirm the version of mojoPortal you were testing with? You can find the version under Administration > System Information.

The reason I ask is because we recently replaced our caching logic with a provider model so we could plug in AppFabric cache, and our new logic uses no locks at all.

The previous implementation did use locking and was based on this thread on stackoverflow. By reading that thread one might think that locking was always needed to update a cache item, but now as I understand it from this article, the cache is threadsafe for updating single objects. From the article:

The ASP.NET Cache and Application objects guarantee that no other concurrently running threads can ever interfere with the single read or write operation you're executing. However, if you need to execute multiple operations on the Cache object in an atomic way, that's a different story.

Since our use of cache is limited to single objects retrieved or added to the cache at a time our previous locking was not needed.

Really the siteSettings object is not needed to service a request for a .txt file but when runAllManagedModulesForAllRequests is true then ASP.NET does handle all requests including those for static files. In our httpmodules I've had it short circuit the logic for other expected static extensions like .js .css etc so that we don't access siteSettings unnecessarily for those requests. I'll add a similar check for .txt to avoid that, though .txt files are not used all that much in typical web sites which I guess is why it didn't occur to me to add the check for that extension when I was adding the checks for other static files.

Thanks and best regards,

Joe

You must sign in to post in the forums. This thread is closed to new posts.