ASP.NET 2.0 web cache insert fails

C

cat

As per Anthony's suggestion, I'm moving this discussion thread to this group.
The history:

We recently moved an older ASP.NET 1.1 code base on to ASP.NET 2.0, .NET 3.0
and Windows 2003 Server SP2. We started experiencing the following issue with
the web cache (the code is straightforward and worked flawlessy before the
upgrade):

Dim o As Object = Cache.Get(key)
If o Is Nothing Then
Cache.Insert(key, GetTheData())
o = Cache.Get(key)
End If

Randomly, Cache.Get(key) returns nothing, even after the application has
been up for a while. Then the Cache.Insert kicks in. Only that the call to
Insert fails with no error and no exception. The subsequent Cache.Get(key)
returns nothing. I've tried to set up the expiration to some remote date in
the future and the sliding expiration; still nothing. I tried something like
this;

Cache.Insert(key, GetTheData(), Nothing,
DateTime.Parse("1/1/9999"),Cache.NoSlidingExpiration)

and

Cache.Insert(key, GetTheData(), Nothing, Cache.NoAbsoluteExpiration,
TimeSpan.FromDays(365))

I even added after the first failed Insert a Thread.Sleep(20) the tried the
Insert again. Didn't work either.

I searched on the Internet and I found a few other posts describing a
similar issue. Yet no reply to any of them so it seems that there is not much
knowledge about this strange issue.

Any idea is highly appreciated.

Thanks,

cat


Could the problem be with the GetTheData method?
You might be better off asking in the

microsoft.public.dotnet.framework.aspnet

group.

--
Anthony Jones - MVP ASP/ASP.NET



Thank you Anthony for taking the time to reply. After my initial posting I
spent some time researching on the Internet and trying out some other things,
so I do have some more information.

1. To answer to your questions/suggestions:
1.a. I will move this discussion to microsoft.public.dotnet.framework.aspnet
1.b. GetTheData was just some very generic pseudocode. The real code
retrieves the information as a dataset based on some criteria, then saves
this dataset to the cache. I am storing a reference to the retrieved dataset
before putting it in the cache, so the code is more like this:

Dim dt As DataSet = GetTheData()
Cache.Insert(key, dt, Nothing,
DateTime.Parse("1/1/2999"),Cache.NoSlidingExpiration)


2. After several days of researching this issue and experimenting various
things, I kind of reached the conclusion that this must be something related
to the memory management. Everything is ok until w3wp (iis worker process)
exceends 400 MB. The computer I am running all those tests has 1 GB RAM.
Subtracting the OS and system cache memory allocations, the 400 MB threshold
means that the computer has under 100 MB of available physical RAM. After
passing that threshold, it seems that .NET runtime refuses to add items to
the cache while also not telling anything to the code (as in, raising some
sort of out of memory exception). Either ASP.NET 2.0 is a more memory hog or
whatever else changed, but this was not happening before upgrading the code
base/site to .NET 3.0 / ASP.NET 2.0 / w2k3 SP2. The site itself is complex
but not that big. It puzzles me why w3wp would grow beyond 400 MB of RAM.

3. I have downloaded, installed and run CLR profiler and ANTS profiler. I am
trying to figure out what's going on at the lower levels. To my surprise,
ANTS (non-Microsoft, not free tool) is worse than CLR profiler (Microsoft
free tool). To this point, it seems that the .net runtime is doing some
allocations (mostly strings) that sit there forever and eat up memory. At
some point I manage to induce a system failure; w3wp gets into a continuous
loop, and IIS fails to ping it therefore it recycles it. I can do that afther
hitting the site for about 10 minutes continuously. All very weird. Never had
those problems before upgrading the code to .NET 3.0 / ASP.NET 2.0 / Win2k3
SP2. A colleague of mine has a similar environment, just SP1 instead of SP2,
so I started wondering whether Microsoft created some weird bug in the heap
allocator in SP2.
 
C

cat

After further testing, I've noticed that on a Windows Server 2003 R2 SP1
machine w3wp stays under 90 MB, on the SP2 machine that I'm doing development
on it goes to around 250 MB with the same code and same pages hit; if I
navigate for a while (like 15-30 minutes) between those pages at some point
the w3wp's memory consumption exceeds 350 MB and it starts going up by itself
with no navigation whatsoever. At that point the IIS ping fails (so w3wp
becomes unresponsive) and so IIS restarts the worker process. Not sure if
this has any relevance, but the pages are a mixture of old ASP with VB COM+
objects and ASP.NET pages with business layer components written in VB.NET
and C#.
 
C

cat

We didn't use that as we deemed it's not needed. The .NET pages use .NET
application & business components. The classical ASP pages use COM+ VB
components. We are in the process of converting the current code base to .NET
and we converted all layers for the features that we managed to convert. The
code base is fairly big, so it will be another while until we are pure .NET
(we are at about 75% of the code base at this point).

From my initial tests, it seems that when hitting only the ASP.NET pages or
only the ASP pages, w3wp memory usage stays relatively constant (still over 2
times higher than on the SP1 machines). The issue seems to get triggered when
navigating between the 2 kinds of pages. I'll run further tests today to
validate this assumption.
 
C

cat

Just to be very clear on this aspect: we have no problem whatsoever with this
code base on the production servers, which are windows 2003 server R2 SP1.
This problem started happening about 2 months ago in development and qa.
During those 2 months we wrote some new features and we installed w2k3 SP2.
I've reviewed the code we changed and there seems to be no relevant change
in the application layer that could have caused any such problem. That would
leave SP2 as suspicious.
 
R

rod

cat,
We had a similar problem after upgrading from .NET 1.1 to 2.0. Our
conclusion was that the .NET 2.0 memory manager is much more aggressive and
when it feels its getting short of memory it removes items from the cache,
sometimes immediately after they are inserted. As evidence of this we saw the
CacheItemRemovedCallback being called between inserting an item and
attempting to retrieve it. One way to fix it is to specify a priority of
NotRemovable which prevents the memory manager from evicting it before you're
ready, but this then places the onus on you to remove it yourself as soon as
possible, either explicitly or via an expiry time.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top