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

Improve genesis state performance at startup #6977

Merged
merged 27 commits into from
Jun 11, 2024

Conversation

fab-10
Copy link
Contributor

@fab-10 fab-10 commented Apr 22, 2024

PR description

This PR takes inspiration from #6952 to improve Besu starts after the first one, specifically when the database is present, when genesis-state-hash-cache-enabled=true, since it completely avoid to reprocess the genesis state, and in case of large genesis files, with may allocations, the startup time drops from many minutes to few seconds, and in any case the genesis allocations are not kept line in memory.

The core of the change is to make the loading of the genesis allocations lazy, so they are only parsed from file when needed, and switching to a streaming parser so they are not all loaded and kept in memory.

Fixed Issue(s)

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

@lyfsn
Copy link
Contributor

lyfsn commented Apr 23, 2024

Hey, I tested the current code; here are some records:

Status Time Memory Allocated
first start (database empty) 14 mins 658 GB
second start (database not empty) 30 s 2.25 GB

Before your refactor, the first start of Besu needed only 7 mins and 186 GB of memory allocated.
The step in there almost completely occupies 645 GB now: https://github.com/fab-10/besu/blob/758adc7d7468e52e17942d3d221116a0ecdda008/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java#L125

The test record is in the jfr record file; you can load it directly using IntelliJ IDEA: https://github.com/lyfsn/besu-starter/blob/main/g-1.jfr

@fab-10 fab-10 force-pushed the refactor-genesis-file-options branch from 08ab687 to 0889ee4 Compare April 24, 2024 16:59
fab-10 added 2 commits April 29, 2024 15:24
# Conflicts:
#	acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java
#	besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
#	besu/src/main/java/org/hyperledger/besu/cli/config/EthNetworkConfig.java
#	besu/src/main/java/org/hyperledger/besu/controller/BesuController.java
#	besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
#	besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java
#	besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java
#	besu/src/test/java/org/hyperledger/besu/RunnerTest.java
#	besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
#	besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java
#	besu/src/test/java/org/hyperledger/besu/cli/config/EthNetworkConfigTest.java
#	besu/src/test/java/org/hyperledger/besu/controller/BesuControllerTest.java
#	config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java
#	config/src/test/java/org/hyperledger/besu/config/JsonUtilTest.java
#	consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeGenesisConfigHelper.java
#	consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java
#	ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java
@fab-10 fab-10 force-pushed the refactor-genesis-file-options branch from 9ca104c to b3a8978 Compare May 2, 2024 15:26
fab-10 added 2 commits May 3, 2024 16:10
# Conflicts:
#	config/src/main/java/org/hyperledger/besu/config/JsonUtil.java
@fab-10 fab-10 force-pushed the refactor-genesis-file-options branch from 829b437 to 07ab31c Compare May 31, 2024 18:14
@fab-10 fab-10 force-pushed the refactor-genesis-file-options branch from 07ab31c to a662895 Compare May 31, 2024 18:52
@fab-10 fab-10 marked this pull request as ready for review June 3, 2024 08:18
@jframe jframe requested a review from macfarla June 10, 2024 21:56
Copy link
Contributor

@ahamlat ahamlat left a comment

Choose a reason for hiding this comment

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

With this PR, starting with a genesis file with more than 1 GiB took 4 minutes and 30 seconds with -Xmx16g.
Without this PR, even with -Xmx16g, the node got killed after 8 minutes.

@fab-10 fab-10 enabled auto-merge (squash) June 11, 2024 10:40
@fab-10 fab-10 merged commit c62f192 into hyperledger:main Jun 11, 2024
40 checks passed
@fab-10 fab-10 deleted the refactor-genesis-file-options branch June 11, 2024 14:18
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