diff --git a/chain/store/index.go b/chain/store/index.go index 7edbf251f..8f3e88417 100644 --- a/chain/store/index.go +++ b/chain/store/index.go @@ -2,6 +2,8 @@ package store import ( "context" + "os" + "strconv" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/abi" @@ -9,6 +11,19 @@ import ( "golang.org/x/xerrors" ) +var DefaultChainIndexCacheSize = 32 << 10 + +func init() { + if s := os.Getenv("LOTUS_CHAIN_INDEX_CACHE"); s != "" { + lcic, err := strconv.Atoi(s) + if err != nil { + log.Errorf("failed to parse 'LOTUS_CHAIN_INDEX_CACHE' env var: %s", err) + } + DefaultChainIndexCacheSize = lcic + } + +} + type ChainIndex struct { skipCache *lru.ARCCache @@ -19,7 +34,7 @@ type ChainIndex struct { type loadTipSetFunc func(types.TipSetKey) (*types.TipSet, error) func NewChainIndex(lts loadTipSetFunc) *ChainIndex { - sc, _ := lru.NewARC(8192) + sc, _ := lru.NewARC(DefaultChainIndexCacheSize) return &ChainIndex{ skipCache: sc, loadTipSet: lts, diff --git a/chain/store/store.go b/chain/store/store.go index d34fdbe5f..24d8c408b 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -7,6 +7,7 @@ import ( "encoding/json" "io" "os" + "strconv" "sync" "github.com/filecoin-project/specs-actors/actors/crypto" @@ -47,6 +48,18 @@ var log = logging.Logger("chainstore") var chainHeadKey = dstore.NewKey("head") var blockValidationCacheKeyPrefix = dstore.NewKey("blockValidation") +var DefaultTipSetCacheSize = 8192 + +func init() { + if s := os.Getenv("LOTUS_CHAIN_TIPSET_CACHE"); s != "" { + tscs, err := strconv.Atoi(s) + if err != nil { + log.Errorf("failed to parse 'LOTUS_CHAIN_TIPSET_CACHE' env var: %s", err) + } + DefaultTipSetCacheSize = tscs + } +} + // ReorgNotifee represents a callback that gets called upon reorgs. type ReorgNotifee func(rev, app []*types.TipSet) error @@ -85,7 +98,7 @@ type ChainStore struct { func NewChainStore(bs bstore.Blockstore, ds dstore.Batching, vmcalls vm.SyscallBuilder) *ChainStore { c, _ := lru.NewARC(2048) - tsc, _ := lru.NewARC(4096) + tsc, _ := lru.NewARC(DefaultTipSetCacheSize) cs := &ChainStore{ bs: bs, ds: ds,