Skip to content
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

Conversation

PastaPastaPasta
Copy link
Member

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.

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@PastaPastaPasta PastaPastaPasta added this to the 22.1 milestone Nov 21, 2024
@DashCoreAutoGuix
Copy link

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.

@PastaPastaPasta PastaPastaPasta force-pushed the refactor-minimize-cs_main-contention-quorum-signing-minimal branch from 0034da5 to f827bfd Compare November 21, 2024 18:28
@DashCoreAutoGuix
Copy link

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.

@PastaPastaPasta PastaPastaPasta force-pushed the refactor-minimize-cs_main-contention-quorum-signing-minimal branch from f827bfd to 3d67771 Compare November 21, 2024 18:32
@DashCoreAutoGuix
Copy link

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.

Copy link

@UdjinM6 UdjinM6 left a 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

@PastaPastaPasta
Copy link
Member Author

PastaPastaPasta commented Nov 21, 2024

this should be feat, not refactor imo but code LGTM

but it doesn't change observable behavior? maybe more of a perf:?

@UdjinM6
Copy link

UdjinM6 commented Nov 21, 2024

It does change internal logic a bit though. perf sounds good I guess.

@PastaPastaPasta PastaPastaPasta changed the title refactor: add in quorumBaseBlockIndexCache to reduce cs_main contention perf: add in quorumBaseBlockIndexCache to reduce cs_main contention Nov 21, 2024
@DashCoreAutoGuix
Copy link

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.

@PastaPastaPasta
Copy link
Member Author

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;
Copy link
Collaborator

@knst knst Nov 22, 2024

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

Suggested change
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;

Copy link
Member Author

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?

Copy link
Collaborator

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"

Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 3d67771

@PastaPastaPasta PastaPastaPasta merged commit 69995ee into dashpay:develop Nov 22, 2024
28 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants