web application memory usage with HttpRuntime.Cache
I've an application where we store datasets in HttpRuntime.Cache for Se开发者_如何学Golect operations ONLY (alltogether ~20MB of data if the dataset is saved as xml).
We migrated to a new Windows 2008 server x64, where IIS site based Output caching was enabled. Our application pool is set to x64 mode as well. All went well, the application was running with some serious load and about ~ 2GB of memory usage.
With no changes to the application, and no additional traffic, the application started to eat up all memory on the server, that is currently 7GB.
I've tried to disable Output caching, but it didn't help at all. The only way to deal with the problem is to recycle the application pool, but this solution results in the loss of all user sessions.
In my understanding, HttpRuntime.Cache items are global for the application pool. We're only Inserting the items to the Cache on the Application Load event, so there should be no changes whatsoever to the cache items.
With disabled output caching and no additional inserts to the Cache, what could cause the unexpected memory growth?
This sounds like a problem with the Large Objects Heap. Since version 1.0 .NET Garbage collector is notorious for failing to collect large objects from memory. The situation has improved with .net versions but especially on high-load servers there are still problems. Check out these articles to get acquainted with the problem:
http://msdn.microsoft.com/en-us/magazine/cc534993.aspx
http://www.simple-talk.com/dotnet/.net-framework/the-dangers-of-the-large-object-heap/
http://www.alexatnet.com/content/net-memory-management-and-garbage-collector
You can also try to profile the application memory on your development server to see if the problem will appear there.
精彩评论