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

Remove EthHash cache once Besu is synced #5969

Open
ahamlat opened this issue Sep 28, 2023 · 3 comments
Open

Remove EthHash cache once Besu is synced #5969

ahamlat opened this issue Sep 28, 2023 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers mainnet performance ready Epic ready to be worked on snack Small coding task

Comments

@ahamlat
Copy link
Contributor

ahamlat commented Sep 28, 2023

Description

Remove EthHash Cache once Besu node is synced. The cache uses around 400 MiB.
The screenshot below is from a heap dump of a node synced two days ago (without any restart)

image

@non-fungible-nelson non-fungible-nelson added enhancement New feature or request good first issue Good for newcomers TeamGroot GH issues worked on by Groot Team performance TeamRevenant GH issues worked on by Revenant Team mainnet TeamChupa GH issues worked on by Chupacabara Team snack Small coding task labels Oct 2, 2023
@dlutzardo
Copy link
Contributor

Hi @ahamlat!

I have reviewed this issue:

  • I have created a private network using Ethash.
  • I have reviewed code from this part (EthHashCacheFactory, EthHashDescriptor, EthashLight, PoWSolver, etc)
  • I have analyzed the JVM heap.

There is no problem with the memory, it is normal use. Exist a very long array of int in memory for each EthHashDescriptor (field 'cache'), this is used during block validation (PoW).

EthHashCacheFactory has a maximum of 5 cached elements (instances of EthHashDescriptor). For each (EthHash.EPOCH_LENGTH * 2) an instance of EthHashDescriptor is generated (EPOCH_LENGTH = 30000) but only the last 5 will be in EthHashCacheFactory. The cache key is calculated in this way: "Long.divideUnsigned(numblock, EthHash.EPOCH_LENGTH * 2)" => 60000 blocks have the same cache key (same EthHashDescriptor)

The validation process for a block obtains the corresponding EthHashCacheFactory for that block, if it does not exist it is generated.

If you restart the node, you will see in the heap that there is only one instance of EthHashCacheFactory (little memory at that moment) but if you check the memory 2 or 3 days later you will see that there are 5 elements in memory of EthHashCacheFactory, the JVM heap is high (420MB on your network, 84 MB x 5 = 420MB). The EthHashCacheFactory size depends on the network configuration.

It is not a problem. Someone decided it was correct 5 elements cached in EthHashCacheFactory. The last 5 generated and used are cached, although your node is synchronized you will have 5 elements when your node is started for a long time, or very different numbers of blocks have been validated.

In my test ethhash network this is the heap of the JVM, there are 5 cached elements of 20MB. The field 'cache' of EthHashDescriptor has 20MB (20MB x 5 = 100MB)
heap_dump_node_ethhash_2

@ahamlat
Copy link
Contributor Author

ahamlat commented Feb 6, 2024

Thanks @dlutzardo for reviewing this issue and for the detailed explanation.
I didn't give a detailed context for the issue. It's actually more related to Ethereum Mainnet, once the node is sync'ed, it is running with PoS and there in no need to keep the cache in memory.
The only way we have currently to free up this memory on Ethereum mainnet is to restart the node at least once after it is sync'ed.

@dlutzardo
Copy link
Contributor

You are welcome.
I understand the situation, and I agree that it is necessary to restart the node.

@macfarla macfarla added ready Epic ready to be worked on and removed TeamGroot GH issues worked on by Groot Team TeamRevenant GH issues worked on by Revenant Team TeamChupa GH issues worked on by Chupacabara Team labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers mainnet performance ready Epic ready to be worked on snack Small coding task
Projects
None yet
Development

No branches or pull requests

4 participants