ethereum / trin

An Ethereum portal client: a json-rpc server with nearly instant sync, and low CPU & storage usage
365 stars 113 forks source link

feat: implement dynamic pruning strategy #1295

Closed morph-dev closed 4 months ago

morph-dev commented 4 months ago

What was wrong?

Current pruning logic for IdIndexedV1Store is to delete up to 5% of storage, but no more than 100 elements. However, even 100 elements is too slow on big databases (e.g. 35GB that are currently used). It can take up to a second and sometimes even longer. This wouldn't be such a big problem if this wouldn't block other read/writes.

How was it fixed?

The idea is to have dynamic number of items that we delete. The PruningConfig allows us to set parameters, for this dynamic strategy:

Also added logic for handling the zero storage capacity to prune the db (if non-empty) and set radius to zero.

To-Do

njgheorghita commented 4 months ago

It seems like this might be relevant... Taking into account #1228 and that (IMO) we will sooner rather than later want to support this, along with a "max db" size (aka a user has 100 gbs of disk space they want to contribute, we'll actually spin up 10 nodes of 10gbs under the hood). Once that's implemented, we'll have a consistent max db size, which means we really don't have to worry about improving the pruning mechanism to support large dbs and can optimize db performance against a fixed target (eg a 10gb storage). Assuming that my description is the direction we're heading, does this pr still make sense?

pipermerriam commented 4 months ago

we'll actually spin up 10 nodes of 10gbs under the hood)

I don't think this is how the architecture will actually work out. I think that under the hood it will be a single 100gb database that is represented in the network across 10 different node-ids.

See: https://github.com/ethereum/portal-network-specs/issues/283#issuecomment-2037869161

morph-dev commented 4 months ago

Together with what Piper said, I would add that there is benefit for smaller dbs as well (as we can purge more there).

In general, I would say it's better to monitor and adjust in any scenario. For example:

morph-dev commented 4 months ago

@carver I do disagree with the proposed changes about pruning number changes, but not strongly :). Willing to discuss it more before merging.

I'm going to merge this and do a followup PR if needed.