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

[Merged by Bors] - use state cache to optimise historical state lookup #4228

Closed
wants to merge 4 commits into from

Conversation

int88
Copy link
Contributor

@int88 int88 commented Apr 24, 2023

Issue Addressed

#3873

Proposed Changes

add a cache to optimise historical state lookup.

Additional Info

N/A

@int88 int88 changed the title [WIP] use state cache to optimise historical state lookup use state cache to optimise historical state lookup Apr 27, 2023
@int88
Copy link
Contributor Author

int88 commented Apr 27, 2023

@michaelsproul PTAL :)

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's heading in the right direction. Have you done any manual testing to see how the performance is? E.g. try requesting a state at slot 8190 in the period, then request the state one slot later. The 2nd request should be almost instant.

Once the change to the low restore point is made I'll do some testing myself

beacon_node/store/src/hot_cold_store.rs Outdated Show resolved Hide resolved
@michaelsproul michaelsproul added waiting-on-author The reviewer has suggested changes and awaits thier implementation. optimization Something to make Lighthouse run more efficiently. database labels Apr 27, 2023
@michaelsproul
Copy link
Member

@int88 Do you mind renaming the flag to --historic-state-cache-size? I'd prefer the longer name to clarify that it only caches states from the freezer DB, and to avoid it conflicting with another state cache added in the future (e.g. my branch #3206 adds a state cache for the hot database).

The implementation is looking really good though, thanks for your efforts! 😊

@int88
Copy link
Contributor Author

int88 commented Apr 28, 2023

@michaelsproul updated :)

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested the performance improvement on one of my archive nodes and it was fantastic!

First I loaded state 6336000 which took 65 seconds:

$ time ssz_state.sh 6336000 > /dev/null

Executed in   65.82 secs      fish           external
   usr time    1.31 millis  400.00 micros    0.91 millis
   sys time   15.44 millis  128.00 micros   15.31 millis

Re-loading the same state from the cache took only 250ms!

time ssz_state.sh 6336000 > /dev/null
________________________________________________________
Executed in  259.70 millis    fish           external
   usr time   12.04 millis  219.00 micros   11.82 millis
   sys time   22.69 millis   74.00 micros   22.62 millis

Loading the state at the next slot was also really fast, around 650ms:

time ssz_state.sh 6336001 > /dev/null

________________________________________________________
Executed in  654.11 millis    fish           external
   usr time   13.86 millis  320.00 micros   13.54 millis
   sys time   17.80 millis  111.00 micros   17.69 millis

This is so awesome I think we should add it to the book. I think a section on this page would be appropriate (maybe with a warning that it can use a lot of memory): https://lighthouse-book.sigmaprime.io/advanced_database.html

beacon_node/store/src/hot_cold_store.rs Outdated Show resolved Hide resolved
beacon_node/store/src/hot_cold_store.rs Outdated Show resolved Hide resolved
beacon_node/store/src/hot_cold_store.rs Outdated Show resolved Hide resolved
lighthouse/tests/beacon_node.rs Show resolved Hide resolved
@michaelsproul michaelsproul added the v4.2.0 Q2 2023 label May 3, 2023
@int88
Copy link
Contributor Author

int88 commented May 3, 2023

I just tested the performance improvement on one of my archive nodes and it was fantastic!

First I loaded state 6336000 which took 65 seconds:

$ time ssz_state.sh 6336000 > /dev/null

Executed in   65.82 secs      fish           external
   usr time    1.31 millis  400.00 micros    0.91 millis
   sys time   15.44 millis  128.00 micros   15.31 millis

Re-loading the same state from the cache took only 250ms!

time ssz_state.sh 6336000 > /dev/null
________________________________________________________
Executed in  259.70 millis    fish           external
   usr time   12.04 millis  219.00 micros   11.82 millis
   sys time   22.69 millis   74.00 micros   22.62 millis

Loading the state at the next slot was also really fast, around 650ms:

time ssz_state.sh 6336001 > /dev/null

________________________________________________________
Executed in  654.11 millis    fish           external
   usr time   13.86 millis  320.00 micros   13.54 millis
   sys time   17.80 millis  111.00 micros   17.69 millis

This is so awesome I think we should add it to the book. I think a section on this page would be appropriate (maybe with a warning that it can use a lot of memory): https://lighthouse-book.sigmaprime.io/advanced_database.html

Awesome test! And do you mean add the usage of flag historic-state-cache-size and above test result to the advanced_databsae doc?

@michaelsproul
Copy link
Member

Awesome test! And do you mean add the usage of flag historic-state-cache-size and above test result to the advanced_databsae doc?

Just the description of the flag I think 😁 Thanks!

@int88
Copy link
Contributor Author

int88 commented May 4, 2023

@michaelsproul updated!

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tweaked the docs slightly, but happy to merge!

Thank you @int88 for implementing this long-awaited feature!

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels May 5, 2023
@michaelsproul
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request May 5, 2023
## Issue Addressed

#3873

## Proposed Changes

add a cache to optimise historical state lookup.

## Additional Info

N/A


Co-authored-by: Michael Sproul <micsproul@gmail.com>
@bors
Copy link

bors bot commented May 5, 2023

Pull request successfully merged into unstable.

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot changed the title use state cache to optimise historical state lookup [Merged by Bors] - use state cache to optimise historical state lookup May 5, 2023
@bors bors bot closed this May 5, 2023
ghost pushed a commit to oone-world/lighthouse that referenced this pull request Jul 13, 2023
## Issue Addressed

sigp#3873

## Proposed Changes

add a cache to optimise historical state lookup.

## Additional Info

N/A


Co-authored-by: Michael Sproul <micsproul@gmail.com>
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
add a cache to optimise historical state lookup.

N/A

Co-authored-by: Michael Sproul <micsproul@gmail.com>
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
add a cache to optimise historical state lookup.

N/A

Co-authored-by: Michael Sproul <micsproul@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database optimization Something to make Lighthouse run more efficiently. ready-for-merge This PR is ready to merge. v4.2.0 Q2 2023
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants