Optimize memory usage of CNode::setAddrKnown #6066

pull gavinandresen wants to merge 2 commits into bitcoin:master from gavinandresen:setAddrKnown_memory changing 6 files +161 −8
  1. gavinandresen commented at 8:42 pm on April 25, 2015: contributor

    The first pull implements a “rolling bloom filter” class that keeps track of at least the last N elements added (but has a false positive rate when queried whether an element has been added).

    The second uses that class to optimize the memory usage of CNode::setAddrKnown, to a fixed 37K of memory per CNode (from about 650K before any changes, or ~300K after @sipa ’s #6064 ).

  2. sipa commented at 9:29 pm on April 25, 2015: member
    Concept ACK.
  3. Rolling bloom filter class
    For when you need to keep track of the last N items
    you've seen, and can tolerate some false-positives.
    97bd572aef
  4. Replace mruset setAddrKnown with CRollingBloomFilter addrKnown
    Use a probabilistic bloom filter to keep track of which addresses
    we think we have given our peers, instead of a list.
    
    This uses much less memory, at the cost of sometimes failing to
    relay an address to a peer-- worst case if the bloom filter happens
    to be as full as it gets, 1-in-1,000.
    
    Measured memory usage of a full mruset setAddrKnown: 650Kbytes
    Constant memory usage of CRollingBloomFilter addrKnown: 37Kbytes.
    
    This will also help heap fragmentation, because the 37K of storage
    is allocated when a CNode is created (when a connection to a peer
    is established) and then there is no per-item-remembered memory
    allocation.
    
    I plan on testing by restarting a full node with an empty peers.dat,
    running a while with -debug=addrman and -debug=net, and making sure
    that the 'addr' message traffic out is reasonable.
    (suggestions for better tests welcome)
    eea15ff4f4
  5. gavinandresen force-pushed on Apr 26, 2015
  6. gavinandresen commented at 6:52 pm on April 26, 2015: contributor
    Changed the first commit to pick @sipa ’s nit (replace array of 2 pointers to bloom filters with plain-old private members that are initialized in the constructor; less code is better).
  7. sipa commented at 12:43 pm on April 27, 2015: member
    Tested ACK
  8. laanwj added the label Improvement on Apr 29, 2015
  9. laanwj commented at 7:26 am on April 29, 2015: member
    Concept ACK
  10. laanwj commented at 1:47 pm on April 30, 2015: member
    Closing as #6064 includes this
  11. laanwj closed this on Apr 30, 2015

  12. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 12:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me