-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
perf: add in quorumBaseBlockIndexCache to reduce cs_main contention #6422
perf: add in quorumBaseBlockIndexCache to reduce cs_main contention #6422
Conversation
Guix Automation has failed due to the HEAD commit not being signed by an authorized core-team member. Please rebase and sign or push a new empty signed commit to allow Guix build to happen. |
0034da5
to
f827bfd
Compare
Guix Automation has failed due to the HEAD commit not being signed by an authorized core-team member. Please rebase and sign or push a new empty signed commit to allow Guix build to happen. |
f827bfd
to
3d67771
Compare
Guix Automation has began to build this PR tagged as v22.1.0-devpr6422.3d67771f. A new comment will be made when the image is pushed. |
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.
this should be feat
, not refactor
imo but code LGTM
utACK 3d67771
but it doesn't change observable behavior? maybe more of a |
It does change internal logic a bit though. |
Guix Automation has completed; a release should be present here: https://github.com/dashpay/dash-dev-branches/releases/tag/v22.1.0-devpr6422.3d67771f. The image should be on dockerhub soon. |
As expected; after testnet testing, contention over cs_main related to this line went from 20% -> 0% On rc.1 cs_main contention represents ~30% of contention (although I previously observed it at ~40%), using this PR, cs_main contention was only ~18% of total contention. Still about 10% of this 18% is related to llmq/quorums, so should try to cache the chain tip as well. But this PR appears to be producing the expected results. |
@@ -252,6 +252,10 @@ class CQuorumManager | |||
mutable Mutex cs_cleanup; | |||
mutable std::map<Consensus::LLMQType, unordered_lru_cache<uint256, uint256, StaticSaltedHasher>> cleanupQuorumsCache GUARDED_BY(cs_cleanup); | |||
|
|||
mutable Mutex cs_quorumBaseBlockIndexCache; | |||
// On mainnet, we have around 62 quorums active at any point; let's cache a little more than double that to be safe. | |||
mutable unordered_lru_cache<uint256 /*quorum_hash*/, const CBlockIndex* /*pindex*/, StaticSaltedHasher, 128 /*max_size*/> quorumBaseBlockIndexCache; |
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: accordingly code-style, members should start for m_
Class member variables have a m_ prefix.
https://github.com/dashpay/dash/blob/master/doc/developer-notes.md?plain=1#L88-L90
mutable unordered_lru_cache<uint256 /*quorum_hash*/, const CBlockIndex* /*pindex*/, StaticSaltedHasher, 128 /*max_size*/> quorumBaseBlockIndexCache; | |
mutable unordered_lru_cache<uint256 /*quorum_hash*/, const CBlockIndex* /*pindex*/, StaticSaltedHasher, 128 /*max_size*/> m_baseblock_index_cache; |
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.
Yeah; we should probably do a refactor for whole dash headers like this and rename. Thoughts?
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.
for whole dash headers
I would not do it. Adding new one - add them in new style. Renaming all old one just for sack of renaming doesn't worth IMO. But in case of any refactoring around it is a good cause to do it.
For example, bitcoin does it everytime when code is refactored, for example bitcoin#21148 - created new class, moved data there and all members got proper nice names such as "mapOrphanTransactionsByPrev" -> "m_outpoint_to_orphan_it"
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.
utACK 3d67771
Issue being fixed or feature implemented
subset of #6418; only includes the new quorumBaseBlockIndexCache, doesn't include the caching of the chain-tip, as that introduced regressions I'm still debugging.
What was done?
introduce a LRU cache for quorumHash -> const CBlockIndex*; this should significantly reduce cs_main contention during high transaction load.
How Has This Been Tested?
Ran tests locally; let's see CI happy, and I also intend to run this on a testnet MN first and see the level of contention reduction
Breaking Changes
None
Checklist:
Go over all the following points, and put an
x
in all the boxes that apply.