Memory issues

Topics: Developer Forum, User Forum
Apr 15, 2009 at 5:30 PM
I am using  single instance of SharedCache at the moment.  This works well but I am experiencing issues with memory usage, the footprint shown in Notify currently is

127.0.0.1 5263 objects
132374 kb

The usage of the SharedCache.WinService.exe service shown in Processes is 598mb

This is more than 4 times the size of the cache itself, I might be missing something obvious here, but I'd expect the cache to be of the same order of memory as the amount of memory used by the service.

This just continues to rise at about 4 times the level of the stored cache.

Any thoughts?

Thanks


Apr 15, 2009 at 5:46 PM
http://sharedcache.codeplex.com/WorkItem/View.aspx?WorkItemId=9559 

please check if this could help you.

regards,
roni    
Apr 16, 2009 at 12:57 AM
Roni,

Thanks very much for the super prompt response, however I'm not sure I really follow.  The link you sent doesn't seem to suggest any resolution and doesn't appear to be directly related to the issue I'm having.

Currently when I look at the cache using Notify utility shows as having 120mb, but the when using task manager to look at the processes the windows service is using 1.2GB of memory!  This doesn't really have anythign to do with the fill factor, more to do with the fact that I'm caching 120mb of data using sharedcache, but using 1.2gb of RAM.

A part from that the sharedcache looks a great product, congratulations on what must have been an awful lot of hard work....

Any ideas?

Matt

ronischuetz wrote:

From: ronischuetz

http://sharedcache.codeplex.com/WorkItem/View.aspx?WorkItemId=9559 

please check if this could help you.

regards,
roni    
Apr 16, 2009 at 8:20 AM

Hi Matt,

how much data is used by Shared Cache is firstly depend on your server configurations:

CacheAmountOfObjects="200" - The maximum size of the objects in the Cache in MB. To make it unlimited, use value -1 which is the default
 in case of -1 you can receive OutOfMemoryException when the server is not able anymore to receive data.
CacheAmountFillFactorInPercentage="90" - If the cache received the fillfactor it will start to throw away unused items from the cache suggested is a value between: 85% - 95%. Default value is 90% and only used if you set CacheAmountOfObjects different then -1.
ServiceCacheCleanup="LRU" - Keys which can be used: "CACHEITEMPRIORITY", "LRU", "LFU", "TIMEBASED", "SIZE", "LLF", "HYBRID".

another intersting configuration is the timed interval you can also define: 

ServiceCacheCleanupThreadJob="1000" - Expire thread interval, if the cache contains data which expires this background thread cleans the cache up [milliseconds].
   1  sec  -> 1000; 30 sec  -> 30000; 1 min  -> 60000; 1  hour -> 3600000; 1 day  -> 86400000; do not define a bigger value then this, the system will fail to read it - its an int 32 value. In case -1 is configured the Thread will be killed after startup.

the server does not prevent from you also to add 500 MB to the cache but once you add more data, a background thread starts to purge your data based on defined cleanup algorithm. The cleanup starts once the needed ram is more then 90% of 200 mb - here it starts to purge your data until it get back to 180mb. Upon purging it can take some seconds until .Net garbage collector
releases all sources - only then you able to identify this over taskmanager. With specific tolls like process explorer from sysinternals (http://www.sysinternals.com/) you able to monitor data like:

# Bytes in all Heaps: This counter is the sum of four other counters; Gen 0 Heap Size; Gen 1 Heap Size; Gen 2 Heap Size and the Large Object Heap Size. This counter indicates the current memory allocated in bytes on the GC Heaps.

# GC Handles: This counter displays the current number of GC Handles in use. GCHandles are handles to resources external to the CLR and the managed environment. Handles occupy small amounts of memory in the GCHeap but potentially expensive unmanaged resources.

# Gen 0 Collections: This counter displays the number of times the generation 0 objects (youngest; most recently allocated) are garbage collected (Gen 0 GC) since the start of the application. Gen 0 GC occurs when the available memory in generation 0 is not sufficient to satisfy an allocation request. This counter is incremented at the end of a Gen 0 GC. Higher generation GCs include all lower generation GCs. This counter is explicitly incremented when a higher generation (Gen 1 or Gen 2) GC occurs. _Global_ counter value is not accurate and should be ignored. This counter displays the last observed value.

# Gen 1 Collections: This counter displays the number of times the generation 1 objects are garbage collected since the start of the application. The counter is incremented at the end of a Gen 1 GC. Higher generation GCs include all lower generation GCs. This counter is explicitly incremented when a higher generation (Gen 2) GC occurs. _Global_ counter value is not accurate and should be ignored. This counter displays the last observed value.

# Gen 2 Collections: This counter displays the number of times the generation 2 objects (older) are garbage collected since the start of the application. The counter is incremented at the end of a Gen 2 GC (also called full GC). _Global_ counter value is not accurate and should be ignored. This counter displays the last observed value.

I hope this gives you a better understanding how Shared Cache is working. If you have additinaionl questions please feel free to extend your questions.

regards,
roni

Apr 17, 2009 at 12:44 AM
Thanks for the in depth reply, I think I follow most of what you are saying however I still don't see how this relates directly to the issue I have.

My issue is this, the amount of memory used by the Shared Cache windows process is huge, currently it uses 2GB (as shown in Task Manager, and Process Explorer), but the amount of this actually used to store objects according to Notify is 150MB.  So that is 1.85GB of RAM being used by the service, to handle a 150mb cache.

Maybe I'm missing something but this just doesn't seem normal.  Why does the windows service use so much RAM to store so little actual data in the cache.  Could this be an issue with running SharedCache 32 bit, on a 64 bit platform, or is it expected behaviour for the memory footprint to be over 10 times the size of the cache being stored?

Many thanks for your help, much appreciated.

Matt



ronischuetz wrote:

From: ronischuetz

Hi Matt,

how much data is used by Shared Cache is firstly depend on your server configurations:

CacheAmountOfObjects="200" - The maximum size of the objects in the Cache in MB. To make it unlimited, use value -1 which is the default
 in case of -1 you can receive OutOfMemoryException when the server is not able anymore to receive data.
CacheAmountFillFactorInPercentage="90" - If the cache received the fillfactor it will start to throw away unused items from the cache suggested is a value between: 85% - 95%. Default value is 90% and only used if you set CacheAmountOfObjects different then -1.
ServiceCacheCleanup="LRU" - Keys which can be used: "CACHEITEMPRIORITY", "LRU", "LFU", "TIMEBASED", "SIZE", "LLF", "HYBRID".

another intersting configuration is the timed interval you can also define: 

ServiceCacheCleanupThreadJob="1000" - Expire thread interval, if the cache contains data which expires this background thread cleans the cache up [milliseconds].
   1  sec  -> 1000; 30 sec  -> 30000; 1 min  -> 60000; 1  hour -> 3600000; 1 day  -> 86400000; do not define a bigger value then this, the system will fail to read it - its an int 32 value. In case -1 is configured the Thread will be killed after startup.

the server does not prevent from you also to add 500 MB to the cache but once you add more data, a background thread starts to purge your data based on defined cleanup algorithm. The cleanup starts once the needed ram is more then 90% of 200 mb - here it starts to purge your data until it get back to 180mb. Upon purging it can take some seconds until .Net garbage collector
releases all sources - only then you able to identify this over taskmanager. With specific tolls like process explorer from sysinternals (http://www.sysinternals.com/) you able to monitor data like:

# Bytes in all Heaps: This counter is the sum of four other counters; Gen 0 Heap Size; Gen 1 Heap Size; Gen 2 Heap Size and the Large Object Heap Size. This counter indicates the current memory allocated in bytes on the GC Heaps.

# GC Handles: This counter displays the current number of GC Handles in use. GCHandles are handles to resources external to the CLR and the managed environment. Handles occupy small amounts of memory in the GCHeap but potentially expensive unmanaged resources.

# Gen 0 Collections: This counter displays the number of times the generation 0 objects (youngest; most recently allocated) are garbage collected (Gen 0 GC) since the start of the application. Gen 0 GC occurs when the available memory in generation 0 is not sufficient to satisfy an allocation request. This counter is incremented at the end of a Gen 0 GC. Higher generation GCs include all lower generation GCs. This counter is explicitly incremented when a higher generation (Gen 1 or Gen 2) GC occurs. _Global_ counter value is not accurate and should be ignored. This counter displays the last observed value.

# Gen 1 Collections: This counter displays the number of times the generation 1 objects are garbage collected since the start of the application. The counter is incremented at the end of a Gen 1 GC. Higher generation GCs include all lower generation GCs. This counter is explicitly incremented when a higher generation (Gen 2) GC occurs. _Global_ counter value is not accurate and should be ignored. This counter displays the last observed value.

# Gen 2 Collections: This counter displays the number of times the generation 2 objects (older) are garbage collected since the start of the application. The counter is incremented at the end of a Gen 2 GC (also called full GC). _Global_ counter value is not accurate and should be ignored. This counter displays the last observed value.

I hope this gives you a better understanding how Shared Cache is working. If you have additinaionl questions please feel free to extend your questions.

regards,
roni

Apr 17, 2009 at 8:25 AM
Hi Matt,

well I think we have to take a look now firstly at your configuration files and your logfiles. Can you prepare something to send me so I
will take a look at it? In general I can say this is not the normal behaviour you describe but it would be helpful if you could share with me
also some code parts like your objects code. I sent you a private message with my contact details and further information.

looking forward to find you a properiate solution.

regards,
roni
Jun 30, 2009 at 8:51 AM

Hi Roni

I have discovered the same issue as Matt described. Is their any new information on this ?

 

regards,

lars

Jun 30, 2009 at 12:07 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.