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

[draft] feat: add more cache to stage sync & live sync #80

Closed
wants to merge 1 commit into from

Conversation

forcodedancing
Copy link
Collaborator

@forcodedancing forcodedancing commented Jul 22, 2024

Description

Try to add another layer of cache.

Rationale

In geth, there are three layers of cache for block importing

  • l1 - cached accounts/storages for the current block execution
  • l2 - cached accounts/storages in difflayers
  • l3 - fast cache for database access

Currently, there are revm state for stage sync (kind of l1&l2 cache); and there are revm state and bundle state for live sync (kind of l1&l2 cache). This pr tries to add l3 cache for stage and live sync.

Example

Initial result is not good.

Stage sync with bsc testnet (from 500W to 1000W blocks)

account hit rate: 878770/26073429 = 3.37%
reth_sync_execution_cache_storage_cache_hit_total 878770
reth_sync_execution_cache_storage_access_total 26073429

storage hit rate: 15310/2696478 = 0.568%
reth_sync_execution_cache_account_cache_hit_total 15310
reth_sync_execution_cache_account_access_total 2696478

Execution stage time:

  • cache version: 38m
  • no cache used: 36m

Live sync with opbnb testnet (from 1 to ~15500 blocks, FCU updates)

account hit rate: 47520/47595 = 99.8%
reth_blockchain_tree_cache_account_cache_hit_total 47520
reth_blockchain_tree_cache_account_access_total 47595

storage hit rate: 30815/126132 = 24.4%
reth_blockchain_tree_cache_storage_cache_hit_total 30815
reth_blockchain_tree_cache_storage_access_total 126132
  • cache version:
image
  • no cache version
image

It seems that sometimes the cached version is better, and sometimes it is much worse. Overall, the execution time does not decrease usually.

Changes

Notable changes:

  • NA

@forcodedancing forcodedancing changed the title feat: add more cache to execution stage [draft] feat: add more cache to execution stage Jul 22, 2024
@forcodedancing forcodedancing changed the title [draft] feat: add more cache to execution stage [draft] feat: add more cache to stage sync & live sync Jul 23, 2024
@forcodedancing
Copy link
Collaborator Author

Tried other cache crate, tried to remove hashmap in the storage cache, the result is also not good. 65f3631#diff-29952b3d47a8eb5fbb763607e8766d35905cbc4c83aa0f200605a525389993ffR36

@forcodedancing
Copy link
Collaborator Author

The implementation of stage sync cache is useless, for there are about 500000 blocks are executed in a batch. In each batch, the state has already been cached in revm state.

[stages.execution]
# The maximum number of blocks to process before the execution stage commits.
max_blocks = 500000
# The maximum number of state changes to keep in memory before the execution stage commits.
max_changes = 5000000
# The maximum cumulative amount of gas to process before the execution stage commits.
max_cumulative_gas = 1500000000000 # 30_000_000 * 50_000_000
# The maximum time spent on blocks processing before the execution stage commits.
max_duration = '10m'

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.

1 participant