wardy
6/28/2007 3:46:00 PM
Hi, I'm hoping someone with some greater caching experience can lend
me a hand, as I'm trying to understand a current caching problem with
our application and design a caching strategy going forward. We have
a v2.0 .NET web application for which items are being flushed from the
cache at unexpected times. I have done some extensive searching on
the subject and read numerous posts and MSDN articles, but I can't
seem to pin down my problem.
To try and get to the bottom of things, I have been testing caching on
my local machine. I'm running at 2GB of physical RAM, using IIS5 and
I haven't modified the processModel setting in my machine.config, so
my available memory should be 60% of my RAM, or 1200 MB. From reading
articles, it would appear that the maximum I should be using to avoid
outofmemory exceptions is 800MB due to virtual address space sizes,
but at this point I'm not worried about those errors.
I have run through 5 separate tests with my performance monitor and
have received the following average statistics at the point when my
cache is resetting for the reason "underused" a.k.a evicted (the items
are added with High priority in the cache. I am adding 3 datasets, of
size 3.3MB, 0.8MB, and 0.9MB, to the cache on application startup):
ASP.NET Apps v 2.0.50727
Cache API Entries = 2.4
Cache API Hit Ratio = 100
Cache API Hits = 5944
Cache API Misses = 0
Cache API Turnover Rate = 0
Cache Total Entries = 26.8
Cache Total Hit Ratio = 76.8214
Cache Total Hits = 996.6
Cache Total Misses = 148.8
Cache Total Turnover Rate = 0
Memory
Available MBytes = 109.8
Process (aspnet_wp)
Handle Count = 929.4
Private Bytes = 66126643.2
Thread Count = 22.6
Virtual Bytes = 258403532.8
According to the documents I have read, the cache would begin
recycling in the following conditions:
1. The ASP.NET Cache will drop entries and induce garbage collections
when "Memory\Available MBytes" is less than or equal to 10% of the
total physical RAM. To be safe, you should not allow this performance
counter to be within 15% of the total physical RAM. In regard to
performance, it would be better to reduce the number of cache entries/
cache size, use an explicity expiration policy on cache entries, or to
purchase more RAM than to allow the application to run in such low
memory conditions.
2. The ASP.NET Cache will drop entries and induce garbage collections
when "Process(w3wp/aspnet_wp)\Private Bytes" is greater than or equal
to approximately 80% of the worker process memory limit (and/or cache
privateBytesMemoryLimit in v2.0). The worker process memory limit can
be set in machine.config <processModel memoryLimit/> for
aspnet_wp.exe, or in the IIS metabase for w3wp.exe (see "Maximum used
memory (in megabytes)" on Application Pool Properties Recycling tab).
In v2.0, there is also a <cache privateBytesMemoryLimit/>.
If you look at the numbers, I certainly do not approach the issue in
number 2....(unless the process reaches 960 MB of private bytes I
shouldn't recycle, and the average I had was approx 66 MB of use).
However, it does appear that #1 is the reason my cache was recycling
(my average available megabytes was 109 and 10% of my physical RAM
would be 200MB).
Now for the questions:
1. Why did the cache not recycle as soon as the Available MBytes
reached 200 MB (I observed the figure while testing and it did not
recycle the cache until the number was much lower than 200)?
2. Am I understanding the caching mechanism correctly?
3. What is the fix for reducing the number of caching recycles (short
of making the NotRemovable designation on the cache items)?
4. Is there a problem with the size of the items I am caching?
5. Would changing the processModel setting affect this behaviour?
6. I've queried for the HttpRuntime.Cache.EffectivePrivateBytesLimit
and received the following value 1,287,651,328 (basically 1200 MB) -
is this value based on the processModel setting?
Thanks