Skip to content

Conversation

gavinandresen
Copy link
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 ).

@sipa
Copy link
Member

sipa commented Apr 25, 2015

Concept ACK.

@sipa sipa mentioned this pull request Apr 25, 2015
For when you need to keep track of the last N items
you've seen, and can tolerate some false-positives.
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)
@gavinandresen
Copy link
Contributor Author

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).

@sipa
Copy link
Member

sipa commented Apr 27, 2015

Tested ACK

@laanwj
Copy link
Member

laanwj commented Apr 29, 2015

Concept ACK

@laanwj
Copy link
Member

laanwj commented Apr 30, 2015

Closing as #6064 includes this

@laanwj laanwj closed this Apr 30, 2015
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants