Skip to content

Add lru cache for loading commit from blockstore #2844

Closed
osmosis-labs/cometbft
#76

Description

@ValarDragon

Feature Request

Summary

Whenever a peer is lagging by more than 1 block, we load the commit for the height they were on and send them the whole commit (per code comment. Admittedly I haven't looked long, but I don't see how it's currently sending the whole commit vs just a single vote from it). Source

Loading the commit requires doing a db read and a proto unmarshal. Source In benchmarks we see the proto unmarshal taking a large number of heap allocations, and this is likely duplicate work. (Unmarshalling the same block commit)

We should keep a small LRU cache for height to unmarshalled commit to reduce the memory pressure here. I suspect the same maybe helpful for block parts as well.

In v37 we saw that this was around 70GB of heap allocation on a query serving node over 1-2 hours. (Will paste memprofile later)

I do not know the total system impact it has, but a 70GB ram allocation is very high.

Proposal

Add a simple lru cache in blockstore for loading commit and block parts

Activity

  1. added
    enhancement
    needs-triage
    on Apr 18, 2024
  2. cason commented on Apr 18, 2024

    @cason

    Definitely. This LRU cache can be implemented at the store, in my opinion, so no need for code changes in the reactor.

  3. cason commented on Apr 18, 2024

    @cason

    The gossipDataRoutine was recently refactored (#2663).

    We load block parts here. If the peer is still lagging behind in the next iteration, we load another block part. Although block parts are not stored together, so we have to load them one by one (source).

  4. added this to the 2024-Q2 milestone on Apr 22, 2024
  5. added a commit that references this issue on May 15, 2024
    46e2484
  6. moved this from Todo to Done in CometBFTon May 15, 2024
  7. added 3 commits that reference this issue on May 15, 2024
    cd2e6e4
    24aacf7
    3686b32
  8. added 3 commits that reference this issue on May 15, 2024
    8c16cf4
    8a0f481
    f97bee9
  9. added a commit that references this issue on May 25, 2024
    0c10bd5
  10. added a commit that references this issue on May 28, 2024
    3c23771
  11. added a commit that references this issue on May 28, 2024
    8d09b54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

consensusenhancementneeds-triagestorage

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions