Last post May 05, 2011 07:38 AM by MdV
Apr 15, 2011 02:43 PM|MdV|LINK
I'm adding an item to cache with an expiration set to 8 minutes, and I'm writing to a log file in the onRemove callback. Although the expiration timespan is set to 8 minutes, I can see in my logs that the onRemove callback runs every 1 minute or so.
This is how I insert the item into cache:
HttpRuntime.Cache.Add("CacheItemKey", "Test", Nothing, _
DateTime.MaxValue, TimeSpan.FromMinutes(8), _
New CacheItemRemovedCallback(AddressOf CacheItemRemovedCallback))
Why is the 8 minute timespan ignored?
Apr 15, 2011 06:18 PM|p3tar|LINK
Whati is the CacheItemRemovedReason reason in your CacheItemRemovedCallback delegate?... DependencyChanged, Expired, Removed, Underused...
Apr 17, 2011 05:35 AM|MdV|LINK
The reason is "Removed".
Apr 18, 2011 07:23 AM|MdV|LINK
It turns out that the whole application is restarting every one minute, so the cache item is removed because of that.
But I don't understand why the application would restart so often. There are no updates to the /bin directory or any other .Net related directory like App_GlobalResources. And the server is not low on memory.
But still the restarts seem to happen spontaneously.
Any ideas what else could cause the spontaneous restart on every minute?
Apr 18, 2011 09:24 AM|MdV|LINK
I found several articles explaining how to get more information on the reason for application restarts. So now I'm logging several things in the Application_End event in Global.asax, and that gives me this:
The hosting environment shut down the application domain.
HostingEnvironment initiated shutdown
HostingEnvironment caused shutdown
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
Not very informative!
Now how do I find out why "The hosting environment shut down the application domain" (= reason ApplicationShutdownReason.HostingEnvironment) ?
Apr 18, 2011 12:20 PM|p3tar|LINK
Is this happening on your local web server/IIS or application is deployed on (shared) hosting environment?
From the message I believe that the problem is the worker process recycling and if the issue is a process recycling (because of a crash) logging application domain restart reason will probably tell you the same message every single time.
App domains or worker process may restart for may reasons, so you should try to gather user mode dumps to find the problem, maybe one of these articles could help you:
Apr 18, 2011 12:36 PM|MdV|LINK
Thank you for your reply.
Unfortunately, the spontaneous restarts are happening in a shared hosting environment, so I can't follow up on the links you provided. They don't happen in my local test environment.
Are there ways to capture more info about the restarts in a shared hosting environment?
Apr 18, 2011 12:44 PM|p3tar|LINK
With shared hosting
that there are not
options left (if any...), but
to contact your
hosting provider and
ask them for help/assistance about the
Apr 19, 2011 02:11 AM|sirdneo|LINK
Since you are in shared hosting environment, first discuss the situation with your hosting provider. Also you can try configuring application pool appropriately to reduce the frequency of event.
May 05, 2011 07:38 AM|MdV|LINK
It turns out there was a 'virtual memory limit' of 300Mb set for the application pool, which was hit almost immediately after starting the application. This caused the application pool to recycle so often.
The 'virtual memory limit' is now changed into a 'private memory limit', and now the application runs fine.