[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

help with .NET cache and cache eviction

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

3 Answers

Alvin Bruney [MVP]

6/30/2007 10:33:00 PM

0

The cache behavior is overly aggressive in 2.0. What that means is that
cache items are evicted with much less tolerance than previous versions of
the framework. I know of no bullet proof way to prevent this from happening.

It concerns me that an item of 3megs is being stored in the cache. Actually,
this is likely impossible so only some parts of the item can remain in L2
cache, the rest has to be paged in when required. That may be the source of
your problem right there. To eliminate/confirm just remove that particular
item and run your tests again.

If that is the problem, consider a redesign of your cached items.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
https://www.microsoft.com/MSPress/books/...
OWC Black Book www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


"wardy" <wardy1975@gmail.com> wrote in message
news:1183045535.428034.193230@i13g2000prf.googlegroups.com...
> 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
>


wardy

7/3/2007 12:47:00 PM

0

Hi Alvin,

Thanks for the response....will try your suggestion of removing that
item from the cache and doing my tests again (that being said, on my
PC at least it makes sense how it behaves - however, we have clients
whose cache is evicted on the very first request, and another where it
is never evicted, with similar loads, just different web server
hardware - the one that evicts immediately is a virtual server)....in
the meantime, are you saying that a 3 Meg item is too big for the
cache? That seems strange given the amount of push that the Microsoft
documentation has on using cache to store datasets - but I may have
misunderstood the proper use of the cache (for that particular item,
we have approx 14,000 rows of data in the dataset).

However, if that is the case that the size is really too big (again,
the fact it works fine in one of our environments is odd), then you
are right we need to re-address our cache strategy and most likely
adopt a singleton based approach to store our datasets in the server
memory rather than the cache - this gives us greater control over the
behaviour as well, since from your post controlling the eviction of
the cache is somewhat black-box.

Thanks

Alvin Bruney [MVP]

7/4/2007 2:39:00 PM

0

Hang on a second, cache is stored in server memory (unless specifically
stored outside in SQL server). Note that the cache service is still stored
in server memory except that it is outside the worker process. The thing you
need to ask yourself is this: does it make sense to store that much data in
memory as opposed to requerying it. I can't really imagine that you will
need all of the 14k rows of data. You may need a smaller common subset -
that you can cache. The cache isn't free, there is a resource cost that is
associated with storing items in memory. The cache makes sense only if that
resource cost brings a noted performance improvement. Otherwise, fire
queries and move the load to the database if the eviction is an issue.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
https://www.microsoft.com/MSPress/books/...
OWC Black Book www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


"wardy" <wardy1975@gmail.com> wrote in message
news:1183466828.071793.293200@k29g2000hsd.googlegroups.com...
> Hi Alvin,
>
> Thanks for the response....will try your suggestion of removing that
> item from the cache and doing my tests again (that being said, on my
> PC at least it makes sense how it behaves - however, we have clients
> whose cache is evicted on the very first request, and another where it
> is never evicted, with similar loads, just different web server
> hardware - the one that evicts immediately is a virtual server)....in
> the meantime, are you saying that a 3 Meg item is too big for the
> cache? That seems strange given the amount of push that the Microsoft
> documentation has on using cache to store datasets - but I may have
> misunderstood the proper use of the cache (for that particular item,
> we have approx 14,000 rows of data in the dataset).
>
> However, if that is the case that the size is really too big (again,
> the fact it works fine in one of our environments is odd), then you
> are right we need to re-address our cache strategy and most likely
> adopt a singleton based approach to store our datasets in the server
> memory rather than the cache - this gives us greater control over the
> behaviour as well, since from your post controlling the eviction of
> the cache is somewhat black-box.
>
> Thanks
>