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

Increase regen historical state cache size #5613

Merged
merged 4 commits into from
Apr 25, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion beacon-chain/db/kv/regen_historical_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kv
import (
"context"
"fmt"
"runtime"

lru "github.com/hashicorp/golang-lru"
"github.com/pkg/errors"
Expand Down Expand Up @@ -56,7 +57,10 @@ func (kv *Store) regenHistoricalStates(ctx context.Context) error {
if err != nil {
return err
}
cacheState, err := lru.New(int(params.BeaconConfig().SlotsPerEpoch) * 2)
// Using max possible size to avoid using DB to save and retrieve pre state (slow)
// The size is 80 because block at slot 43772 built on top of block at slot 43693.
// That is the worst case.
cacheState, err := lru.New(80)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a global constant? Just so its not hardcoded into a parameter.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! Done

if err != nil {
return err
}
Expand Down Expand Up @@ -125,6 +129,9 @@ func (kv *Store) regenHistoricalStates(ctx context.Context) error {
// Flush the cache, the cached states never be used again.
cacheState.Purge()

// Manually garbage collect as previous cache will never be used again..
terencechain marked this conversation as resolved.
Show resolved Hide resolved
runtime.GC()

return nil
}

Expand Down