HighTechTalks DotNet Forums  

OutOfMemoryException during caching

ASP.net Caching microsoft.public.dotnet.framework.aspnet.caching


Discuss OutOfMemoryException during caching in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Alexander Inochkin
 
Posts: n/a

Default OutOfMemoryException during caching - 04-13-2005 , 04:08 AM






Hi!

I use System.Web.Caching.Cache object in ASP.NET application to cache a lot
of large (~100K) and small (~2-5K) objects.
I use Windows Server 2003, IIS, ASP.NET v.1.1 ( all patched! ).

When I run my application on server with 1 Gb Ram all work OK. The memory
using w3wp.exe growing up to ~700M,
farther some items removed from cache and so on.

When I upgrade server memory up to 2 Gb the memory using w3wp.exe growing up
to about 1G-1.4G and application exception OutOfMemoryException occured, but
cached items has not removed from cache!!!

How can I fix this strange behavior?

Thanks for any help.
Alexander Inochkin.



Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default RE: OutOfMemoryException during caching - 04-13-2005 , 11:24 PM






Hello Alexander,

How did you set the Memory recycling for the application pool? If your
ASP.NET consume too much memory, a recycling is reqiured. Also, I suggest
you may consider reduce the life time (its expire property) of cached
object so that it won't cost too much of memory.

Luke


Reply With Quote
  #3  
Old   
Alexander Inochkin
 
Posts: n/a

Default Re: OutOfMemoryException during caching - 04-14-2005 , 01:53 AM



OK. I can set Memory recycling for my application. It will restart
application. But I do not need to restart one.
I need to remove (flush) old cache entries when low memory occured.

I notice, application works correctly on the windows server 2003 system with
1Gb RAM.
How it happens? I insert new objects in the cache. Application use more and
more of memory.
Some point some cached objects removed from cache without any errors. It is
normal. (In my application I can control count
cached objects.)

But on the system with 2 Gb RAM (!!!) the application raises exception
OutOfMemoryException and does not remove (flush)
old cached objects!!!

Cache work incorrect on the system with larger memory!!!
Why the .NET does not remove (flush) the old objects from cache in this
case?


Quote:
Hello Alexander,

How did you set the Memory recycling for the application pool? If your
ASP.NET consume too much memory, a recycling is reqiured. Also, I suggest
you may consider reduce the life time (its expire property) of cached
object so that it won't cost too much of memory.

Luke




Reply With Quote
  #4  
Old   
AT
 
Posts: n/a

Default Re: OutOfMemoryException during caching - 04-14-2005 , 03:18 AM



Hello Alexander,

By default the ASP.NET's max process memory limit is 60% of the total
system memory. Since your application may consume 1.4G memory, a recycling
is necessary here.

And, the "Out of memory" error may be related to other issues, for example,
memory fragments or incorrect code in your application. How did you find
the "Out of memory" error is related to the cached objects? Did it occur
when you add a object to cache?

Luke


Reply With Quote
  #5  
Old   
gabe garza
 
Posts: n/a

Default Re: OutOfMemoryException during caching - 04-14-2005 , 08:51 PM



Alexander,

Are you setting all unused objects to "unreachable"?

The GC doesn't know when an object is not being used in a running program
until you mark it as "unreachable".
In C# that's done with setting an object to null, in VB it's setting it to
nothing.
Of course if you have a Close() and/or a Dispose method you'd call that
first to make sure everything is cleaned up properly. I think on certian
objects in VB there might be something else to call, but bottom line is,
always clean up your objects before making them "unreachable" for the GC to
see it.
After cleaning up your objects the GC will at some point in time remove
those "unreachable" objects, unless you call GC yourself.

Are you setting your objects with an expiration (absolute/sliding), if so
are you setting the callback as well. In the callback once an item is
removed from cache you get the object passed to you. At that point in the
callback routine you'd again, Close()/Dispose() and set to "unreachable", or
you can even put it back in the cache too.

Remember, the GC will not touch any object until you mark it as
"unreachable".



"Alexander Inochkin" <alex_i (AT) community (DOT) nospam> wrote

Quote:
OK. I can set Memory recycling for my application. It will restart
application. But I do not need to restart one.
I need to remove (flush) old cache entries when low memory occured.

I notice, application works correctly on the windows server 2003 system
with 1Gb RAM.
How it happens? I insert new objects in the cache. Application use more
and more of memory.
Some point some cached objects removed from cache without any errors. It
is normal. (In my application I can control count
cached objects.)

But on the system with 2 Gb RAM (!!!) the application raises exception
OutOfMemoryException and does not remove (flush)
old cached objects!!!

Cache work incorrect on the system with larger memory!!!
Why the .NET does not remove (flush) the old objects from cache in this
case?


Hello Alexander,

How did you set the Memory recycling for the application pool? If your
ASP.NET consume too much memory, a recycling is reqiured. Also, I suggest
you may consider reduce the life time (its expire property) of cached
object so that it won't cost too much of memory.

Luke






Reply With Quote
  #6  
Old   
Alexander Inochkin
 
Posts: n/a

Default Re: OutOfMemoryException during caching - 04-15-2005 , 05:07 AM



CONCLUSION

I include /3GB key in boot.ini (on the Windows Server 2003, 2Gb RAM)!
It solve my problem... Application grow up to 1.3-1.4 Gb, time from time
flush system.web.caching.cache
and do not throw exception.

I think it is the bug in cache flush algoritm. It can not remove object from
cache correctly when expiration time not appear yet on the Windows System
2Gb RAM.

Thanks for help.


Quote:
I use System.Web.Caching.Cache object in ASP.NET application to cache a
lot of large (~100K) and small (~2-5K) objects.
I use Windows Server 2003, IIS, ASP.NET v.1.1 ( all patched! ).

When I run my application on server with 1 Gb Ram all work OK. The memory
using w3wp.exe growing up to ~700M,
farther some items removed from cache and so on.

When I upgrade server memory up to 2 Gb the memory using w3wp.exe growing
up to about 1G-1.4G and application exception OutOfMemoryException
occured, but cached items has not removed from cache!!!

How can I fix this strange behavior?

Thanks for any help.
Alexander Inochkin.




Reply With Quote
  #7  
Old   
Ben Strackany
 
Posts: n/a

Default Re: OutOfMemoryException during caching - 04-26-2005 , 12:07 PM



Due to memeory fragmentation or the inability to address more than 2gb of
memory, you can get OutOfMemory errors on a machine even if it looks like
you have enough memory left.

http://www.developmentnow.com/blog/2...th-aspnet.html

--
Benjamin Strackany
http://www.developmentnow.com


"Alexander Inochkin" <alex_i (AT) community (DOT) nospam> wrote

Quote:
CONCLUSION

I include /3GB key in boot.ini (on the Windows Server 2003, 2Gb RAM)!
It solve my problem... Application grow up to 1.3-1.4 Gb, time from time
flush system.web.caching.cache
and do not throw exception.

I think it is the bug in cache flush algoritm. It can not remove object
from
cache correctly when expiration time not appear yet on the Windows System
2Gb RAM.

Thanks for help.


I use System.Web.Caching.Cache object in ASP.NET application to cache a
lot of large (~100K) and small (~2-5K) objects.
I use Windows Server 2003, IIS, ASP.NET v.1.1 ( all patched! ).

When I run my application on server with 1 Gb Ram all work OK. The
memory
using w3wp.exe growing up to ~700M,
farther some items removed from cache and so on.

When I upgrade server memory up to 2 Gb the memory using w3wp.exe
growing
up to about 1G-1.4G and application exception OutOfMemoryException
occured, but cached items has not removed from cache!!!

How can I fix this strange behavior?

Thanks for any help.
Alexander Inochkin.






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.