-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Description
I've been seeing 100% cpu usage on one of my bitcoind nodes recently, with transactions taking >60s to be accepted into the mempool. Digging into it, the problem seems to be BOOST_MULTI_INDEX_ENABLE_SAFE_MODE
which was introduced in #24395. That results in iterator destruction taking O(n) time (in the number of other active iterators on the same multi-index) in the worst case, rather than O(1) time, due to keeping the iterators in a singly linked list:
* Iterators are chained in a single attached list, whose header is
* kept by the container. More elaborate data structures would yield better
* performance, but I decided to keep complexity to a minimum since
* speed is not an issue here.
Speed does become an issue here though, as we keep an iterator around for every mempool entry (in vTxHashes
).
This isn't always a problem: presumably in the normal case new iterators are added to the head of the list then removed while they're still roughly at the head of the list, giving O(1) timing; but somehow having a full mempool (and hence TrimToSize actually doing things) triggers worst case behaviour?