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
Mempool multifetch #17139
Mempool multifetch #17139
Conversation
Pull Request Test Coverage Report for Build 7304023557
💛 - Coveralls |
f642f95
to
dd2bb3a
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.
aok
dd2bb3a
to
06b4ffe
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
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.
aok
…ecords up-front, in a single sql query
06b4ffe
to
d08861a
Compare
* update type annotation for CoinStore.get_coin_records to support both List and Set * update the mempool to fetch multiple coin records per query * optimize the slow-path of updating the mempool by fetching all coin records up-front, in a single sql query
* update type annotation for CoinStore.get_coin_records to support both List and Set * update the mempool to fetch multiple coin records per query * optimize the slow-path of updating the mempool by fetching all coin records up-front, in a single sql query
This PR is best reviewed one commit at a time. But the second commit contains the bulk of the changes.
checkpoint merge
Reverse this patch when merging to
main
:Purpose:
This patch improves the disk I/O performance of the mempool by fetching coin records in batches instead of one at a time. It primarily reduces CPU usage when adding spend bundles to the mempool, which is especially critical when updating the mempool through the new-block slow-path.
There are two key changes in this PR:
get_coin_records
The
MempoolManager
andMempool
objects are passed a function from theCoinStore
,get_coin_record
, that looks up a single coin record. The first change is to instead of pass inget_coin_records
. This function fetches multiple coin records in a single query.This change requires updates a lot of tests, which ends up being the build of the changes. The core changes, however, are in
def validate_spend_bundle()
inmempool_manager.py
.new-peak slow-path
The second change (3rd commit) is to, when entering the slow-path to update the peak; fetch all spent coins in a single query, stick the
CoinRecords
in a dictionary. Pass in a local version ofget_coin_records
that only looks up coins from the local dictionary toadd_spend_bundle()
, when adding all the transactions into the new mempool.This turns thousands of individual
CoinRecord
lookups into a single query.Current Behavior:
Mempool
takes a function that can fetch oneCoinRecord
. Coin record are looked up one at a time when validating transactions.New Behavior:
Mempool
takes a function that can fetch multipleCoinRecord
s. Coin record are looked up in a single query.When updating the peak through the slow-path, all coin spends are looked up in a single query, to speed up re-adding the transactions to the new mempool instance.
Testing Notes:
This was tested on IPS machines. The wall-clock time was not improved as much as the CPU usage:
Before
After