ava-labs / avalanchego

Go implementation of an Avalanche node.
https://avax.network
BSD 3-Clause "New" or "Revised" License
2.09k stars 646 forks source link

Only compact after executing a large number of blocks #3065

Closed StephenButtolph closed 1 month ago

StephenButtolph commented 1 month ago

Why this should be merged

After a chain has finished bootstrapping (like the P-chain) it will re-bootstrap every 10 seconds to keep up-to-tip until the full subnet has finished bootstrapping.

Calling db.Compact every 10 seconds (even with a small range of impacted values on disk) significantly reduces the performance of other DB operations.

This can cause the X-chain and C-chain syncing to be significantly slower than before this compaction was added.

How this works

Only compact the bootstrapping database if the number of blocks executed was significant.

How this was tested

StephenButtolph commented 1 month ago

I'm wondering why wouldn't we compact the database inline with the block processing, i.e. within for !haltable.Halted() && iterator.Next() loop.

We tested that and it was less performant than this code. (for executing a single chain).