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

[R4R] improve snap mutex #905

Merged
merged 1 commit into from
Jun 7, 2022

Conversation

forcodedancing
Copy link
Contributor

@forcodedancing forcodedancing commented May 12, 2022

Description

This pr tries to improve block importing by splitting mutex for snap account and storage.

Rationale

The access to snap accounts and snap storage could use different locks to avoid unnecessary race.

Result

  • Before
Dropped 546 nodes (cum <= 0.02mins)
Showing top 40 nodes out of 106
      flat  flat%   sum%        cum   cum%
  3.59mins 90.44% 90.44%   3.59mins 90.44%  sync.(*Mutex).Unlock (partial-inline)
  0.37mins  9.26% 99.71%   2.17mins 54.68%  sync.(*RWMutex).Unlock
         0     0% 99.71%   0.03mins  0.74%  github.com/VictoriaMetrics/fastcache.(*Cache).Set
         0     0% 99.71%   0.03mins  0.74%  github.com/VictoriaMetrics/fastcache.(*bucket).Set
         0     0% 99.71%   0.51mins 12.93%  github.com/ethereum/go-ethereum/core.(*BlockChain).InsertChain
         0     0% 99.71%   0.02mins  0.58%  github.com/ethereum/go-ethereum/core.(*BlockChain).insertChain
         0     0% 99.71%   0.08mins  2.02%  github.com/ethereum/go-ethereum/core.(*StateTransition).TransitionDb
         0     0% 99.71%   0.04mins     1%  github.com/ethereum/go-ethereum/core.(*TxPool).AddRemotes
         0     0% 99.71%   0.04mins     1%  github.com/ethereum/go-ethereum/core.(*TxPool).addTxs
         0     0% 99.71%   0.34mins  8.47%  github.com/ethereum/go-ethereum/core.(*TxPool).runReorg
         0     0% 99.71%   0.05mins  1.14%  github.com/ethereum/go-ethereum/core.(*statePrefetcher).Prefetch.func1
         0     0% 99.71%   0.08mins  1.97%  github.com/ethereum/go-ethereum/core.ApplyMessage
         0     0% 99.71%   0.06mins  1.48%  github.com/ethereum/go-ethereum/core.precacheTransaction
         0     0% 99.71%   0.11mins  2.70%  github.com/ethereum/go-ethereum/core/rawdb.ReadStorageSnapshot
         0     0% 99.71%   0.11mins  2.72%  github.com/ethereum/go-ethereum/core/state.(*StateDB).AccountsIntermediateRoot.func1
         0     0% 99.71%   0.11mins  2.72%  github.com/ethereum/go-ethereum/core/state.(*StateDB).AccountsIntermediateRoot.func2
  • After
Dropped 571 nodes (cum <= 0.02mins)
Showing top 40 nodes out of 111
      flat  flat%   sum%        cum   cum%
  4.54mins 91.33% 91.33%   4.54mins 91.33%  sync.(*Mutex).Unlock (partial-inline)
  0.42mins  8.38% 99.70%   2.28mins 45.96%  sync.(*RWMutex).Unlock
         0     0% 99.70%   0.04mins  0.76%  github.com/VictoriaMetrics/fastcache.(*Cache).Set
         0     0% 99.70%   0.04mins  0.76%  github.com/VictoriaMetrics/fastcache.(*bucket).Set
         0     0% 99.70%   0.45mins  9.08%  github.com/ethereum/go-ethereum/core.(*BlockChain).InsertChain
         0     0% 99.70%   0.03mins  0.55%  github.com/ethereum/go-ethereum/core.(*BlockChain).insertChain
         0     0% 99.70%   0.08mins  1.57%  github.com/ethereum/go-ethereum/core.(*StateTransition).TransitionDb
         0     0% 99.70%   0.04mins  0.81%  github.com/ethereum/go-ethereum/core.(*TxPool).AddRemotes
         0     0% 99.70%   0.04mins  0.81%  github.com/ethereum/go-ethereum/core.(*TxPool).addTxs
         0     0% 99.70%   0.40mins  8.12%  github.com/ethereum/go-ethereum/core.(*TxPool).runReorg
         0     0% 99.70%   0.04mins  0.85%  github.com/ethereum/go-ethereum/core.(*statePrefetcher).Prefetch.func1
         0     0% 99.70%   0.08mins  1.54%  github.com/ethereum/go-ethereum/core.ApplyMessage
         0     0% 99.70%   0.06mins  1.12%  github.com/ethereum/go-ethereum/core.precacheTransaction
         0     0% 99.70%   0.11mins  2.20%  github.com/ethereum/go-ethereum/core/rawdb.ReadStorageSnapshot
         0     0% 99.70%   0.06mins  1.16%  github.com/ethereum/go-ethereum/core/state.(*StateDB).AccountsIntermediateRoot.func1
         0     0% 99.70%   0.06mins  1.17%  github.com/ethereum/go-ethereum/core/state.(*StateDB).AccountsIntermediateRoot.func2

We can see that AccountsIntermediateRoot's block duration has been reduced.

Changes

Notable changes:

  • use different locks for snap account and snap storage

Copy link
Contributor

@setunapo setunapo left a comment

Choose a reason for hiding this comment

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

LGTM

@forcodedancing forcodedancing merged commit 2288373 into bnb-chain:develop Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants