Skip to content

Commit

Permalink
[test] Disable workingset cache in the benchmark test (#3558)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liuhaai committed Jul 20, 2022
1 parent e209d4e commit cc09a6c
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 18 deletions.
12 changes: 6 additions & 6 deletions blockchain/blockdao/blockdao.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ type (
indexers []BlockIndexer
timerFactory *prometheustimer.TimerFactory
lifecycle lifecycle.Lifecycle
headerCache *cache.ThreadSafeLruCache
bodyCache *cache.ThreadSafeLruCache
footerCache *cache.ThreadSafeLruCache
headerCache cache.LRUCache
bodyCache cache.LRUCache
footerCache cache.LRUCache
tipHeight uint64
}
)
Expand Down Expand Up @@ -336,20 +336,20 @@ func createBlockDAO(blkStore filedao.FileDAO, indexers []BlockIndexer, cfg db.Co
return blockDAO
}

func lruCacheGet(c *cache.ThreadSafeLruCache, key interface{}) (interface{}, bool) {
func lruCacheGet(c cache.LRUCache, key interface{}) (interface{}, bool) {
if c != nil {
return c.Get(key)
}
return nil, false
}

func lruCachePut(c *cache.ThreadSafeLruCache, k, v interface{}) {
func lruCachePut(c cache.LRUCache, k, v interface{}) {
if c != nil {
c.Add(k, v)
}
}

func lruCacheDel(c *cache.ThreadSafeLruCache, k interface{}) {
func lruCacheDel(c cache.LRUCache, k interface{}) {
if c != nil {
c.Remove(k)
}
Expand Down
2 changes: 1 addition & 1 deletion blockchain/filedao/filedao_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type (
topIndex atomic.Value
htf db.RangeIndex
kvStore db.KVStore
kvStores *cache.ThreadSafeLruCache //store like map[index]db.KVStore,index from 1...N
kvStores cache.LRUCache //store like map[index]db.KVStore,index from 1...N
deser *block.Deserializer
}
)
Expand Down
2 changes: 1 addition & 1 deletion blockchain/filedao/filedao_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type (
header *FileHeader
tip *FileTip
blkBuffer *stagingBuffer
blkCache *cache.ThreadSafeLruCache
blkCache cache.LRUCache
kvStore db.KVStore
batch batch.KVStoreBatch
hashStore db.CountingIndex // store block hash
Expand Down
4 changes: 2 additions & 2 deletions blockchain/integrity/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ func newChainInDB() (blockchain.Blockchain, actpool.ActPool, error) {
cfg.Consensus.Scheme = config.RollDPoSScheme
cfg.Genesis.BlockGasLimit = genesis.Default.BlockGasLimit * 100
cfg.ActPool.MinGasPriceStr = "0"
cfg.ActPool.MaxNumActsPerAcct = 1000000000
cfg.ActPool.MaxNumActsPerAcct = 10000
cfg.Genesis.EnableGravityChainVoting = false
registry := protocol.NewRegistry()
var sf factory.Factory
kv := db.NewBoltDB(cfg.DB)
sf, err = factory.NewStateDB(cfg, factory.PrecreatedStateDBOption(kv), factory.RegistryStateDBOption(registry))
sf, err = factory.NewStateDB(cfg, factory.PrecreatedStateDBOption(kv), factory.RegistryStateDBOption(registry), factory.DisableWorkingSetCacheOption())
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions db/kvstore_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const (

// memKVStore is the in-memory implementation of KVStore for testing purpose
type memKVStore struct {
data *cache.ThreadSafeLruCache
bucket *cache.ThreadSafeLruCache
data cache.LRUCache
bucket cache.LRUCache
}

// NewMemKVStore instantiates an in-memory KV store
Expand Down
4 changes: 2 additions & 2 deletions db/kvstorewithcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
type kvStoreWithCache struct {
mutex sync.RWMutex // lock for stateCaches
store KVStore
stateCaches map[string]*cache.ThreadSafeLruCache // map having lru cache to store current states for speed up
stateCaches map[string]cache.LRUCache // map having lru cache to store current states for speed up
cacheSize int
}

// NewKvStoreWithCache wraps kvstore with stateCaches
func NewKvStoreWithCache(kvstore KVStore, cacheSize int) KVStore {
return &kvStoreWithCache{
store: kvstore,
stateCaches: make(map[string]*cache.ThreadSafeLruCache),
stateCaches: make(map[string]cache.LRUCache),
cacheSize: cacheSize,
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/iotexproject/go-fsm v1.0.0
github.com/iotexproject/go-p2p v0.3.4
github.com/iotexproject/go-pkgs v0.1.12
github.com/iotexproject/go-pkgs v0.1.13
github.com/iotexproject/iotex-address v0.2.8
github.com/iotexproject/iotex-antenna-go/v2 v2.5.1
github.com/iotexproject/iotex-election v0.3.5-0.20210611041425-20ddf674363d
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,9 @@ github.com/iotexproject/go-p2p v0.3.4 h1:V+Hq4K4lbEI9gAjHqKLpzS4lqCPqjeosRY/LnIp
github.com/iotexproject/go-p2p v0.3.4/go.mod h1:P32N/mwLUWMQ/okMcNLlfBO7iD5ITyBOvN41roKdPdg=
github.com/iotexproject/go-pkgs v0.1.5-0.20210604060651-be5ee19f2575/go.mod h1:ttXhcwrtODyh7JozpJlCml09CjP0pcKqTe2B0MbTGc8=
github.com/iotexproject/go-pkgs v0.1.6/go.mod h1:E+Fl0XQZz56EzXFajFET2yFoRGsIbL6wQooVIkSim3o=
github.com/iotexproject/go-pkgs v0.1.12 h1:WQcGDHxC9d2gv7r+8aBK7IgechL0XflimRkh+xN+ybI=
github.com/iotexproject/go-pkgs v0.1.12/go.mod h1:t5X9kQ1VL5H+L+DC5GmohXnFKlcxaTcRnIBBuydcsTQ=
github.com/iotexproject/go-pkgs v0.1.13 h1:bK48DVenkfYkC4TRoqL77RLFRBE1MUfscCW495kzcC8=
github.com/iotexproject/go-pkgs v0.1.13/go.mod h1:t5X9kQ1VL5H+L+DC5GmohXnFKlcxaTcRnIBBuydcsTQ=
github.com/iotexproject/iotex-address v0.2.4/go.mod h1:K78yPSMB4K7gF/iQ7djT1amph0RBrP3rSkFfH7gNG70=
github.com/iotexproject/iotex-address v0.2.5/go.mod h1:K78yPSMB4K7gF/iQ7djT1amph0RBrP3rSkFfH7gNG70=
github.com/iotexproject/iotex-address v0.2.7/go.mod h1:K78yPSMB4K7gF/iQ7djT1amph0RBrP3rSkFfH7gNG70=
Expand Down
2 changes: 1 addition & 1 deletion state/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type (
twoLayerTrie trie.TwoLayerTrie // global state trie, this is a read only trie
dao db.KVStore // the underlying DB for account/contract storage
timerFactory *prometheustimer.TimerFactory
workingsets *cache.ThreadSafeLruCache // lru cache for workingsets
workingsets cache.LRUCache // lru cache for workingsets
protocolView protocol.View
skipBlockValidationOnPut bool
ps *patchStore
Expand Down
10 changes: 9 additions & 1 deletion state/factory/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type stateDB struct {
registry *protocol.Registry
dao db.KVStore // the underlying DB for account/contract storage
timerFactory *prometheustimer.TimerFactory
workingsets *cache.ThreadSafeLruCache // lru cache for workingsets
workingsets cache.LRUCache // lru cache for workingsets
protocolView protocol.View
skipBlockValidationOnPut bool
ps *patchStore
Expand Down Expand Up @@ -124,6 +124,14 @@ func SkipBlockValidationStateDBOption() StateDBOption {
}
}

// DisableWorkingSetCacheOption disable workingset cache
func DisableWorkingSetCacheOption() StateDBOption {
return func(sdb *stateDB, cfg config.Config) error {
sdb.workingsets = cache.NewDummyLruCache()
return nil
}
}

// NewStateDB creates a new state db
func NewStateDB(cfg config.Config, opts ...StateDBOption) (Factory, error) {
sdb := stateDB{
Expand Down

0 comments on commit cc09a6c

Please sign in to comment.