-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Reduce default mempool size in -blocksonly mode #26471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a surprisingly long time to figure out the rationale here. I'll write down my understanding both to have it validated/corrected, as well as hopefully to inform other people looking at this.
My understanding:
Users running with -blocksonly expect to have a near zero-sized mempool, because it'll only contain transactions broadcasted by their own wallet (disabled by default) or transactions received from whitelisted peers (non-default). As such, when provisioning their system, a user would expect to only have to allocate dbcache amount of memory, instead of currently actually requiring dbcache + maxmempool, which could lead to stability issues.
Without -blocksonly, a user needs to ensure that his system is provisioned to support both the full dbcache and mempool. Since it's provisioned anyway, we might as well use the unused mempool space for dbcache, which is especially helpful during IBD.
The misunderstanding for me was that the resource sharing between dbcache and maxmempool is not a resource optimization (in which case "we would benefit even more with -blocksonly, so why disable the optimization?!") but rather an accounting trick. Users running in -blocksonly should just increase their dbcache by whatever size maxmempool is for a similar effect (but not entirely, as explained below)
If my understanding is correct, I'm Concept ACK (i.e. making resource usage less surprising) but not yet Approach ACK, because:
- this would be a performance degradation for users running
-blocksonlythat don't realize they should update their-dbcache. Users running-blocksonlycould get higher defaultdbcachedefaults, but that seems messy too. - users can't really replicate current behaviour even if they're aware of the change. The intuitive solution would be to increase
-dbcacheby-maxmempool, however,dbcacheis shared by multiple caches, of which the coins cache receives 25-50%. It seems there's no way to allocate an extra 300MB (assuming default) to just the coins cache without increasing thedbcacheby a total of 600MB - 1.2GB?
|
Thanks for your review at this conceptual stage @stickies-v. Your understanding of the problem and solution matches my own, although I had not fully considered the knock-on effect that:
I also concur with you that altering default Therefore I see x options available from here:
In writing the options out like that, my first preference might actually be 1), followed by 3) and last 2). |
I think I'm not in favour of 1 & 3. Imo the direction should always be to reduce exceptional behaviour, if the short-term cost of that change is not exorbitant. I think in this case, the cost (potentially slower IBD which can be fixed with user config) is not exorbitant and increased stability (because of reduction of unexpected behaviour) is a worthwhile improvement. I can think of two other alternatives, both building on top of what you've currently implemented:
|
|
Yes 4) is a possible solution. IMO by the time we hit 5), we're probably almost talking about people who have such an understanding of the system (developers) that they can most likely make the change to the source themselves before compiling if they truely need such fine-grained settings changes. Will leave it as is to see if we get any other suggestions, and mull it over myself... |
FWIW, I have a related thought process for Knots, where it makes sense to leave the coins cache unlimited (and let memory pressure trigger flushing), yet it isn't sane to just increase
|
|
It seems the key issue is "surprising memory usage," i.e.
Given how surprising this is to so many people (including those affected by this problem), I can see how disabling mempool in blocksonly would be the easiest option. But can also see how it's not acceptable for users that rely on the current whitelist relay behavior according to #9569.
|
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
I think this is a neat solution which covers all requirements so implemented it in this second branch (it's also much cleaner implementation-wise). The only question I had was how small is "smaller"? I opted for 5MB in blocksonly mode as this should be enough for quite a few transactions to be relayed for whitelisted peers, I think... If this is preferred I will move it over to this branch...? |
That definitely seems sufficient, and they can still make it higher if they need to. 5MB is the minimum
I think it's a relatively simple change to lessen this problem with minimal side effects? 🤷 though I don't know if we could say we've completely fixed it. fwiw I think it's sensible regardless since we're probably unlikely to need 300MB in blocksonly mode. |
ab64a8a to
dd43259
Compare
|
OK I have moved the commits across, and updated the PR title and description. I also added a new release note commit which I thought was worth it, but happy to be persuaded otherwise. |
dd43259 to
931924f
Compare
aureleoules
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 931924f5cc1dd9c82306a0ce59b62cf5c9276565
Tested with -blocksonly and -blocksonly -maxmempool=n and verified the logs, seems to work as intended.
(Please avoid rebasing when there is no need.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach ACK 931924f5cc1dd9c82306a0ce59b62cf5c9276565, except for setting mempool_opts.max_size_bytes in two different locations and times.
I think this approach tackles a nice balance between addressing the most important issue (node crashing because of unexpected resource usage), reducing additional code overhead (compared to the other approaches considered) and allowing users to maintain existing performance profile without too much admin overhead. The biggest (but manageable) downside is that everyone that upgrades and doesn't manually override -maxmempool will silently experience a performance degradation, especially during IBD. I expect this performance degradation to be manageable, especially since most users that have the resources available, will probably have manually increased their dbcache anyway for IBD, lowering the relative impact of this change.
2789dcd to
ed5ce6d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reACK ed5ce6d0c911ac66bd5870a1711edef03a18ebeb - Wording updated and logic cleaned up since my last review.
stickies-v
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK ed5ce6d0c
ajtowns
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach ACK
When -blockonly is set, reduce mempool size to 5MB unless -maxmempool is also set. See bitcoin#9569
Changes to the default mempool allocation size now documented. Provides users with guidance on the mempool implications of -blocksonly mode, along with instructions on how to re-enable old behaviour.
ed5ce6d to
dceef81
Compare
Adds a release note detailing the new mempool sizing behaviour when running in blocksonly mode, and instruction on how to override the new defaults.
dceef81 to
8e85164
Compare
|
Thanks for the comments, I've updated the branch taking them into consideration. |
ajtowns
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 8e85164
stickies-v
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 8e85164
|
|
||
| /** Default for -maxmempool, maximum megabytes of mempool memory usage */ | ||
| static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300}; | ||
| //** Default for -maxmempool when blocksonly is set */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| //** Default for -maxmempool when blocksonly is set */ | |
| /** Default for -maxmempool when blocksonly is set */ |
| - Since `0.14.0`, unused memory allocated to the mempool (default: 300MB) is shared with the UTXO cache, so when trying to reduce memory usage you should limit the mempool, with the `-maxmempool` command line argument. | ||
|
|
||
| - Do not use this when using the client to broadcast transactions as any transaction sent will stick out like a sore thumb, affecting privacy. When used with the wallet it should be combined with `-walletbroadcast=0` and `-spendzeroconfchange=0`. Another mechanism for broadcasting outgoing transactions (if any) should be used. | ||
| - To disable most of the mempool functionality there is the `-blocksonly` option. This will reduce the default memory usage to 5MB and make the client opt out of receiving (and thus relaying) transactions, except from whitelisted peers and as part of blocks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Instead of whitelisted, it would be good to mention the exact permission flag.
8e85164 doc: release note on mempool size in -blocksonly (willcl-ark) ae79746 doc: Update blocksonly behaviour in reduce-memory (willcl-ark) 1134686 mempool: Don't share mempool with dbcache in blocksonly (willcl-ark) Pull request description: Fixes bitcoin#9526 When `-blocksonly` has been set reduce default mempool size to avoid surprising resource usage via sharing un-used mempool cache space with dbcache. In comparison to bitcoin#9569 which either set `maxmempool` size to 0 when `-blocksonly` was set or else errored on startup, this change will permit `maxmempool` options being set. This preserves the current (surprising?) behaviour of having a functional mempool in `-blocksonly` mode, to permit whitelisted peer transaction relay, whilst reducing average runtime memory usage for blocksonly nodes which either use the default settings or have otherwise configured a `maxmempool` size. To use the previous old defaults node operators can configure their node with: `-blocksonly -maxmempool=300`. ACKs for top commit: ajtowns: ACK 8e85164 stickies-v: re-ACK bitcoin@8e85164 Tree-SHA512: 1c461c24b6f14ba02cfe4e2cde60dc629e47485db5701bca3003b8df79e3aa311c0c967979f6a1dca3ba69f5b1e45fa2db6ff83352fdf2d4349d5f8d120e740d
|
@willcl-ark will you be taking the followups #26471 (comment) and #26471 (comment)? |
|
Yes I can do those @glozow |
47c174d doc: NetPermissionFlags for tx relay in blocksonly (willcl-ark) e325e0f doc: Fix comment syntax error (willcl-ark) Pull request description: Fix syntax error and specify `NetPermissionFlags` for whitelisted tx relay ACKs for top commit: w0xlt: ACK 47c174d Tree-SHA512: eb579dc599a96a3ea79c01ac3e76160ec59cf71c2486c9401da8fbbd96ae756ba647aa9ba874835946bc76ba02782729da788617f982ae5a852139e10e7dfd75
47c174d doc: NetPermissionFlags for tx relay in blocksonly (willcl-ark) e325e0f doc: Fix comment syntax error (willcl-ark) Pull request description: Fix syntax error and specify `NetPermissionFlags` for whitelisted tx relay ACKs for top commit: w0xlt: ACK bitcoin@47c174d Tree-SHA512: eb579dc599a96a3ea79c01ac3e76160ec59cf71c2486c9401da8fbbd96ae756ba647aa9ba874835946bc76ba02782729da788617f982ae5a852139e10e7dfd75
Fixes #9526
When
-blocksonlyhas been set reduce default mempool size to avoid surprising resource usage via sharing un-used mempool cache space with dbcache.In comparison to #9569 which either set
maxmempoolsize to 0 when-blocksonlywas set or else errored on startup, this change will permitmaxmempooloptions being set.This preserves the current (surprising?) behaviour of having a functional mempool in
-blocksonlymode, to permit whitelisted peer transaction relay, whilst reducing average runtime memory usage for blocksonly nodes which either use the default settings or have otherwise configured amaxmempoolsize.To use the previous old defaults node operators can configure their node with:
-blocksonly -maxmempool=300.