Discussion Velocity CTP2 Serious Memory Bug

  • Sunday, January 11, 2009 7:23 PM
     
      Has Code

    When you create an instance of the cachefactory and then don’t use it anymore the memory that was used during the creation of the object is not released. This will have a substantial effect on all web apps or scenarios where a cachfactory might be created multiple times. The symptoms of this will be unusually high memory use one the process and in IIS this will most likely result in your app having to recycle more often since it with overrun its allocated memory more quickly.

    The following code will show an increase of about 500MB yes I mean MegaBytes of memory usage!

    To duplicate put the following code into your app:

     
    Dim CacheFactory1 As CacheFactory = New CacheFactory()  
    For i As Int32 = 1 To 1 * (10 ^ 4)  
        CacheFactory1 = New CacheFactory()  
        CacheFactory1 = Nothing 
    Next 

    There are only two workarounds for this.

    1. Velocity team fixes the bug (and I’m sure they will)
    2. You need to use the same cachefactory object on a static method in your app and reference it every time you want to use the cache. (this works but isn’t optimal in my opinion.)

    I also have a cachingscope that can be used to wrap your caching methods and will post this on codeplex soon. You can wrap it around your caching methods just like a transaction scope and it will manage the locking and connection for you.

    The cachescope can be found here http://www.codeplex.com/CacheScope 

    • Edited by Middletone Tuesday, February 17, 2009 7:00 PM
    •  

All Replies

  • Wednesday, January 14, 2009 3:21 PM
     
     
    You made my day.
    Thanks for the workaround!
  • Wednesday, January 21, 2009 11:13 PM
     
     
    Another possibility is to have your Factory and Cache in a singleton. This guarantee that the object will oly be instantiated once.

    Dalmer Azevedo
  • Saturday, January 31, 2009 6:31 PM
     
     
    Hi 'Middletone' :), a cache factory is not supposed to be created multiple times in an application. Though I agree in some cases you would need multiple of them. Can you be a bit more specific about your scenarios.
    The workaround you mentioned is true and thanks for sharing that with other guys.
    Regarding the memory not getting released issue, we are working on it.
    Thanks,
    Amit.
  • Monday, February 02, 2009 7:54 PM
     
     
     

    Hi,

     

    We have strange situation with Velocity when periodically (every 3 mins) Put portions of data to Velocity cache - by separate windows service app and detect that in several hours (near 5-10 hours) Memory Usage of DistributedCache.exe is about 2-3 Gb in spite of not big portions of data is put there. Therewith get-cachestatistics shows max used memory size 19 Mb. Cluster ttl =86400, cache has only one host with secondaries=0. Did anyone have such a problem and found solution? Take to account that we always update data in cache via Put storing Cache as static property of DistrCache class.

     

    That all seems to be known memory leak issue of Velocity.

    Another example we tried (more simplified) - when we install Velocity with one host, configurated via ClusterConfig.xml and trivial test was done – list of 10 strings was put to cache after that it was extracted and nothing more – just waiting a bit (eg 15 min) – after that you can notice memory usage growth of DistributedCache.exe process. After searching some help in the network, we implemented Singleton to store only one single instances of CacheFactory and Cache but didn’t help.

     

    Because of mechanism of releasing data when highwatermark exceeded we have serious problems now and have to restart cachecluster (1 host) regularly (with enabling spare Velocity instance).

     

    Could you help us with some temporary (till release time) advise to be applied on real-life system using Velocity as any patch, workaround, fix that kind of thing?

     

    Thanks,

     

    Roman Pavlenko,

    http://most.ua/
  • Tuesday, February 03, 2009 7:18 PM
     
     
    Hi Amit,
    I was stuck with the same problem described above! Share your opinion about the problem and its possible fix or workaround please? We'll be compelled to move from Velocity to Memcached if the problem stays.

    Thanks in advance!

    Vladimir Leshchinsky
  • Tuesday, February 17, 2009 6:58 PM
     
     
    I've posted a fix here.  Let me know how it works out.  If you need personallized help with it just send me an email and I'll see whta I can do.

    http://www.codeplex.com/CacheScope