Open ahamlat opened 1 year ago
Hi @ahamlat!
I have reviewed this issue:
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)
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.
You are welcome. I understand the situation, and I agree that it is necessary to restart the node.
Hello @ahamlat I have been looking into this issue and would love to take it up. Look a bit complex since am new but am open to the challenge. Can we have a quick call on how to handle this.
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)