On 2014-14-10 21:17, Jeff McCune wrote:
On Tue, Oct 14, 2014 at 11:57 AM, Henrik Lindberg
<[email protected] <mailto:[email protected]>>
wrote:

    On 2014-14-10 17:36, Ben Ford wrote:

        I have to admit that this email made me feel a little bit dumb.
        Could
        you provide a TL;DR summary that at least provides a little
        context for
        this? Is this something that people writing types, functions, hiera
        backends, or report processors need to concern themselves with?


    Sorry about that - this is mostly if you are contributing to Puppet
    itself, or if you find that your implementation in Ruby (of
    whatever) leaks memory and you need to find the cause.

    If you are following the well beaten path when writing types and
    providers etc. you need not worry. If you are writing caching in any
    form you are potentially causing memory leaks and the tips here apply.


Is my understanding that the way caching was implemented, by using a
full resource type object as the Hash key in a class variable, is what
caused the leak?  Specifically, the resource type would never be cleaned
up by the garbage collector because it's a hash key in a class instance
variable, correct?

Here:
https://github.com/puppetlabs/puppet/pull/3188/files#diff-d8c96ce74a7f29debda40750462bd248L249

Yes, two problems;

1. The object used as the key does not provides hash and equals and thus the cache would grow because of lack of cache hits unless the same instance was again used as a key (which it isn't in a new instance of an environment). Had equals and hash been correctly implemented on type, we would possibly see a slower leak since some environments would not introduce new keys. (We would have other issues though).

2. The class level variable (@@nondeprecating_type) holds on to every type seen and does not change when an environment expires. When an environment expires, and the cache holds on to a type then a very large set of objects are bound in memory since there are circular references from that type binding to almost everything loaded in an environment (via known_resource_types). Hence my analogy of "you think you are holding on to a banana, but it comes with a Gorilla and its Jungle".

- henrik


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/m1kgrn%24uhq%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to